Broaden detection for plugin entrypoint files#343
Conversation
We still want the filename flexibility and ability to use namespaces in regular first-party plugin entrypoints, not just single-file MU-plugins
|
I'm not sure I understand this change; are we allowing If so, that is not the same as allowing Requiring function definitions inside plugin directories to be in What's the use case for loosening this restriction? |
|
@rmccue I hadn't intended to alter the side-effects change, the nested plugin files are definitely meant to be held to the same standard — declarations or side-effects, never both. What's happened here is that I ended up conflating Now, you can argue this is just a convenience over I'll adjust or recreate the PR to back out the loosening of |
|
Got it, that makes sense - I think it's fine to declare a namespace and potentially some eg It's often most convenient to set a file/dir const directly from that file: <?php
namespace HM\Whatever;
const PLUGIN_FILE = __FILE__;
const PLUGIN_DIR = __DIR__;I'm surprised this isn't allowed already given we use it frequently 🤔 Did we regress? |
Maybe...? It does feel surprising. We excluded |
Yeah, this updated the sniff to add load.php in NamespaceDirectoryNameSniff but |
In #337 we added support to opt single-file MU-plugins out from rules prohibiting namespaces outside of
inc, and requiring namespaced code to live within anamespace.phpfile — both rules would discourage namespacing within plugin entrypoint files.This conclusion also applies to nested plugins, such as traditionally-structured plugin folders within
mu-plugins/and also the defaultplugins/folder. If we're working on a first party plugin within a project that uses HMCS, we want to be consistent about how we treat plugin entrypoints throughout first party code.This PR refactors the MU-Plugin detection trait to recognize all plugin entrypoint files, even those within wrapping folders. By convention, we support
<plugin-name>/plugin.phpand<plugin-name>/<plugin-name>.php.