Skip to content

Permit single-file mu-plugins#337

Merged
kadamwhite merged 2 commits into
mainfrom
client-mu-plugins-support
Jun 22, 2026
Merged

Permit single-file mu-plugins#337
kadamwhite merged 2 commits into
mainfrom
client-mu-plugins-support

Conversation

@kadamwhite

@kadamwhite kadamwhite commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

I reviewed use of HMCS across a variety of VIP and Altis projects and noticed a recurring configuration in project PHPCS to disable the rules which prevent the use of single-file MU plugins, e.g. to drop a small hm-thirdpartyplugin-integration.php which simply registers a few hooks to customize third-party code and doesn't benefit practically from the more robust folder-based code structure.

I believe this should be permitted by our standards, and this PR "paves the cowpath" by adjusting the ruleset to avoid false-flagging files like this from needing to be organized into inc/namespaces, and to permit them to have side-effects.

Sets up tests to demonstrate the issues in this ruleset that prevent
easy use of single-file mu-plugin patterns, which have pragmatic uses
in many codebases and should still require namespaces, etc.
Permits files which are direct children of mu-plugins or client-mu-plugins
to have sideeffects and to not require a folder-based structure.

Proper file organization is still recommended but in many cases a full
inc folder is overkill for a small mu-plugin which adjusts third-party
plugin functionality, etcetera.
$path = str_replace( DIRECTORY_SEPARATOR, '/', $path );
}

return (bool) preg_match( '#/(?:client-)?mu-plugins/[^/]+\.php$#', $path );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is plugins-mu also used?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in any projects that I've worked on in the past 3–4 years, my inclination is to leave that one out as it's a confusing pattern

@kadamwhite kadamwhite merged commit f6e4c51 into main Jun 22, 2026
3 checks passed
@kadamwhite kadamwhite deleted the client-mu-plugins-support branch June 22, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants