-
Couldn't load subscription status.
- Fork 33
dev: use WP_Abilities_Registry::$instance instead of adding a new global
#19
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
dev: use WP_Abilities_Registry::$instance instead of adding a new global
#19
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #19 +/- ##
========================================
Coverage ? 90.64%
Complexity ? 99
========================================
Files ? 7
Lines ? 556
Branches ? 0
========================================
Hits ? 504
Misses ? 52
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong preference here. WordPress uses globals for many fundamental singletones like $post, $wp_scripts, $wp_rest_server. However, we need to make it fully testable and be able to reset the instance between test runs.
Also unfortunately, our PHPUnit CI is passing when the tests itself fail - I'll take a look at that too! 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using reflection makes the test pass 👍

What
This PR changes
WP_Abilities_Registryto store it's instance on::$instance, instead of on a newglobal $wp_abilitiesvariable.(Note: I'm just code-reviewing and leaving feedback. If you think this warrants a wider discussion I can open a matching issue, otherwise I think a discussion here following by [accept | reject] is enough)
Why
Global variables are hard-to-type-and-test antipatterns. Just because legacy WP code used them before there were better patterns doesn't mean we need to introduce new ones.
Using a private instance gives core contributors and end-devs more insight into usage, and as developers working on the Abilities API, we get a much smaller surface for breaking changes to worry about.