Abilities API: Allow registration after init#12401
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket: https://core.trac.wordpress.org/ticket/65583
What
Allows Abilities API registration through
wp_register_ability()andwp_register_ability_category()at any point after theinitaction has fired.The
wp_abilities_api_initandwp_abilities_api_categories_inithooks remain the recommended registration points because they make abilities/categories available as soon as the registries initialize. The public wrappers now reject only genuinely too-early registration beforeinit.Why
The current one-shot registration window is fragile for consumers that initialize after
init, such as REST-initialized adapters, Composer-loaded packages, and headless runtimes that boot WordPress before loading extension code. In those caseswp_register_ability()returnsnulland the ability is absent, with the diagnostic only visible through_doing_it_wrong().Public ecosystem examples of this class of issue:
wp_abilities_api_inithook fires before adapter initializes mcp-adapter#117wp_abilities_api_initmcp-adapter#135_doing_it_wrongnotice — Ability "mcp-adapter/get-ability-info" not found" on admin pages woocommerce/woocommerce#65272This change keeps the pre-
initguard, but restores the public wrapper as the supported path after WordPress has booted, instead of requiring consumers to call the registry singleton directly.Tests
Adds coverage that:
wp_abilities_api_initafterinitand remain discoverable viawp_has_ability(),wp_get_ability(), andwp_get_abilities();wp_abilities_api_categories_initafterinit;initregistration still fails with_doing_it_wrong().Local verification:
php -l src/wp-includes/abilities-api.phpphp -l tests/phpunit/tests/abilities-api/wpRegisterAbility.phpphp -l tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.phpvendor/bin/phpcs --standard=phpcs.xml.dist src/wp-includes/abilities-api.php tests/phpunit/tests/abilities-api/wpRegisterAbility.php tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.phpgit diff --checkFull PHPUnit was not run locally because this checkout does not have
wp-tests-config.phpconfigured.AI assistance