Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamingConventions/PrefixAllGlobals: allow non-prefixed declarations for pluggable functions and classes #2286

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 4, 2023

While the PrefixAllGlobals sniff already allowed for WP native constants which can be user declared, it did not allow for explicitly pluggable functions and classes being declared in plugins/themes.

I'm quite surprised actually that this was not reported as a bug so far.

Either way, fixed now.

In both cases, a case-insensitive name comparison is done as PHP natively treats function names and class names case-insensitively.

The lists added are based on some prelim sniffs created for issue #1803 and WP Core 6.3-beta2.

Notes:

  • When generating these lists, I've explicitly excluded the wp-includes/compat.php file (which contains the polyfills for PHP native functionality).
  • I've intentionally included the Twenty* theme related functions and classes as WPCS should also allow for being used by child themes of those themes.
  • I've excluded polyfills for new WP functionality from the Twenty* themes (which allow the themes to use those functions when running on older WP versions), as those functions aren't intentionally pluggable by WP itself.
  • I've marked a number of functions/classes with a // Deprecated comment based on manual verification (and the declaration being in the wp-includes/pluggable-deprecated.php file). While it would, of course, be better if those would not be "plugged", it is not for this sniff to have an opinion on that and declaring these without a prefix should be allowed.
  • In the $pluggable_functions list, I've intentionally commented two functions out as those are declared nested within another function and do not look intentionally pluggable. This may need further verification, but at least this way it is documented why these are not included in the list.

Includes tests.

…or pluggable functions and classes

While the `PrefixAllGlobals` sniff already allowed for WP native constants which can be user declared, it did not allow for explicitly pluggable functions and classes being declared in plugins/themes.

I'm quite surprised actually that this was not reported as a bug so far.

Either way, fixed now.

In both cases, a case-insensitive name comparison is done as PHP natively treats function names and class names case-insensitively.

The lists added are based on some prelim sniffs created for issue 1803 and WP Core 6.3-beta2.

Notes:
* When generating these lists, I've explicitly excluded the `wp-includes/compat.php` file (which contains the polyfills for PHP native functionality).
* I've intentionally included the Twenty* theme related functions and classes as WPCS should also allow for being used by child themes of those themes.
* I've _excluded_ polyfills for new WP functionality from the Twenty* themes (which allow the themes to use those functions when running on older WP versions), as those functions aren't intentionally pluggable by WP itself.
* I've marked a number of functions/classes with a `// Deprecated` comment based on manual verification (and the declaration being in the `wp-includes/pluggable-deprecated.php` file).
    While it would, of course, be better if those would not be "plugged", it is not for this sniff to have an opinion on that and declaring these without a prefix should be allowed.
* In the `$pluggable_functions` list, I've intentionally commented two functions out as those are declared nested within another function and do not look _intentionally_ pluggable. This may need further verification, but at least this way it is documented why these are not included in the list.

Includes tests.
@jrfnl jrfnl added Type: Bug Type: Enhancement Status: Review ready Focus: WP interoperability Doing things the WP way, prefer using WP functionality over userland/PHP native labels Jul 4, 2023
@jrfnl jrfnl added this to the 3.0.0 milestone Jul 4, 2023
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

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

@GaryJones GaryJones merged commit 2744c45 into develop Jul 4, 2023
35 checks passed
@GaryJones GaryJones deleted the feature/prefixallglobals-allow-for-pluggable-functions-classes branch July 4, 2023 11:22
@jrfnl jrfnl mentioned this pull request Aug 20, 2023
36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Focus: WP interoperability Doing things the WP way, prefer using WP functionality over userland/PHP native Status: Review ready Type: Bug Type: Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants