Skip to content

Abilities API: Allow registration after init#12401

Open
chubes4 wants to merge 1 commit into
WordPress:trunkfrom
chubes4:abilities-late-registration
Open

Abilities API: Allow registration after init#12401
chubes4 wants to merge 1 commit into
WordPress:trunkfrom
chubes4:abilities-late-registration

Conversation

@chubes4

@chubes4 chubes4 commented Jul 3, 2026

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/65583

What

Allows Abilities API registration through wp_register_ability() and wp_register_ability_category() at any point after the init action has fired.

The wp_abilities_api_init and wp_abilities_api_categories_init hooks 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 before init.

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 cases wp_register_ability() returns null and the ability is absent, with the diagnostic only visible through _doing_it_wrong().

Public ecosystem examples of this class of issue:

This change keeps the pre-init guard, 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:

  • abilities can be registered outside wp_abilities_api_init after init and remain discoverable via wp_has_ability(), wp_get_ability(), and wp_get_abilities();
  • ability categories can be registered outside wp_abilities_api_categories_init after init;
  • pre-init registration still fails with _doing_it_wrong().

Local verification:

  • php -l src/wp-includes/abilities-api.php
  • php -l tests/phpunit/tests/abilities-api/wpRegisterAbility.php
  • php -l tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php
  • vendor/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.php
  • git diff --check

Full PHPUnit was not run locally because this checkout does not have wp-tests-config.php configured.

AI assistance

  • AI assistance: Yes
  • Tool(s): opencode — GPT 5.5 (OpenAI)
  • Used for: Drafted the patch, tests, and PR text from the public Trac ticket and source-code investigation; the submitter reviewed and remains responsible for the change.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props extrachill.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant