#65569 closed enhancement (fixed)
Abilities API category requirement is a design question worth settling
| Reported by: | gziolo | Owned by: | gziolo |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Abilities API | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Registering an ability requires a category, the category must be registered first on its own hook, and there is no built-in catch-all to fall back on. Building real abilities surfaced how much friction this creates during first-time integration. The requirement is defensible, but the current shape makes a simple ability harder to register than it needs to be, and it is worth deciding deliberately whether that is the experience we want.
Context
The guardrails already exist. Every failure mode below emits a _doing_it_wrong() notice today: registering on the wrong hook, naming a category that is not registered, and omitting the category entirely. The catch is that _doing_it_wrong() surfaces through PHP's error channel, so it is visible in a WP_DEBUG development setup and silent in a default configuration. A developer iterating without WP_DEBUG on sees only a NULL return and has nothing to go on, which is what made the category rules feel like undocumented failures rather than a contract.
One clarification worth recording: the core registered site and user categories are available for general use.
The question
The category requirement is real, but its ergonomics pull in three directions and we should pick one on purpose rather than by default.
Grow the default categories. As core introduces new abilities, ship more built-in categories so authors have a fitting home without registering their own. This keeps categorization meaningful, but it does not help the plugin that still wants its own namespace, and it grows the surface core has to maintain.
Make the category optional. Fall back to a single catch-all when none is given, so a simple ability registers with no ceremony. This removes the sharpest edge, at the cost of weaker categorization and a bucket that tends to collect everything. The fallback name matters here, since general reads as a respectable default while uncategorized signals a junk drawer, and that choice quietly shapes how readily authors reach for it.
Keep it required, improve discoverability. Leave the contract as is and close the gap with documentation, stating plainly that these functions return NULL on failure, that WP_DEBUG surfaces the reason, and that categories register on wp_abilities_api_categories_init before abilities on wp_abilities_api_init. This preserves the design intent and costs the least, but keeps a required field that some will still read as friction.
These are not mutually exclusive. The documentation improvement is worth doing regardless of which way the requirement itself lands.
Working pattern
For reference, the sequence that registers cleanly today:
add_action( 'wp_abilities_api_categories_init', function() { wp_register_ability_category( 'myplugin', [ 'label' => 'My Plugin', 'description' => 'Abilities for my plugin.', ] ); } ); add_action( 'wp_abilities_api_init', function() { wp_register_ability( 'myplugin/get-posts', [ 'label' => 'Get Posts', 'description' => 'Retrieve posts with optional filtering.', 'category' => 'myplugin', 'input_schema' => [ /* ... */ ], 'output_schema' => [ /* ... */ ], 'permission_callback' => fn() => current_user_can( 'edit_posts' ), 'execute_callback' => function( $input ) { /* ... */ }, 'meta' => [ 'mcp' => [ 'public' => true ] ], ] ); } );
References
- Requirements doc: Ability exposure requirements
- Slack discussion: #core-ai thread
Attachments (1)
Change History (16)
This ticket was mentioned in Slack in #core-ai by gziolo. View the logs.
4 months ago
#3
@
4 months ago
- Keywords has-patch has-unit-tests added
- Milestone Awaiting Review → 7.2
@khokansardar, appreciate your feedback. @sachinrajcp123, thank you for providing a working patch that implements these recommendations. It looks good based on a quick scan.
This ticket was mentioned in Slack in #core-ai by gziolo. View the logs.
4 months ago
This ticket was mentioned in PR #13157 on WordPress/wordpress-develop by @gziolo.
3 months ago
#6
This makes the category argument optional when registering an ability. When it is omitted or empty, the registry assigns the built-in uncategorized category.
Previously, the registry only validated a category when one was provided, but WP_Ability still required the argument during instantiation. This left registrations without a category unable to succeed. Applying the fallback before validation keeps explicit invalid category values rejected while allowing simple or transitional registrations to omit a category.
The change:
- registers the
uncategorizedcategory with the other core ability categories; - defaults omitted or empty category values to
uncategorized; - updates the public API documentation; and
- adds regression coverage for the fallback and invalid category types.
Props @Sachin7907 for the patch and @itzmekhokan for feedback.
## Testing
git diff --checkpasses.- PHPCS passes for all six changed PHP files.
- PHPUnit was attempted with
npm run test:php -- tests/phpunit/tests/abilities-api, but Docker was not running. The local fallback could not connect to the configuredmysqlhost.
## Use of AI Tools
AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-5
Used for: Reviewing the existing local diff, running validation, and preparing the commit and pull request description. The implementation was pre-existing and reviewed by the submitter.
#12
@
5 days ago
I apologize for missing this. I'd prefer to have this reverted, here's why:
When we introduced Abilities we knew we'd eventually have moments wherein we need to retrieve them in subsets, given that we'll quite likely have scenarios where there are hundreds of Abilities in a given site. AI tooling is one scenario for this.
If we started with Ability Categories being optional, then it wouldn't be possible to make them required later. And if they're optional, a significant number of Abilities will be uncategorized, which brings us back to the same effective problem.
I grant that it is an inconvenience, but I believe a minor one, and one that wouldn't surface to non-technical users. Unless we have a clear case for a problem outside of inconvenience and confusion, I think it's best to keep it the way it is. For confusion, we should update the docs to help folks understand, not change it.
This ticket was mentioned in PR #15462 on WordPress/wordpress-develop by @gziolo.
5 days ago
#13
Restores the requirement for abilities to specify a registered category, following comment 12. An omitted category now returns null with a _doing_it_wrong() notice instead of registering the ability as uncategorized.
This selectively reverts the optional-category behavior from r63343: it removes the built-in fallback, retains invalid-category validation, and updates the existing tests. The documentation explains why categories are required, how to reuse registered categories, and the registration hook order. The failure guidance and subsequent documentation improvements are preserved.
Testing
- PHPCS passes for all six changed PHP files.
git diff --checkpasses.npm run test:php -- tests/phpunit/tests/abilities-apiwas attempted, but Docker stalled before PHPUnit started. Running the suite in the existing PHP container also stalled; both commands were stopped.- The native fallback,
vendor/bin/phpunit tests/phpunit/tests/abilities-api, could not connect because the configuredmysqlhostname could not be resolved. PHPUnit results remain unverified.
Use of AI Tools
AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-6
Used for: Inspecting the original change, implementing the targeted revert, updating tests and inline documentation, running validation checks, and preparing the commit and pull request description. The scope and documentation wording were refined with the submitter.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Taking the 2nd-opinion. I'd reframe: this is two fixable bugs and one real taste call, not three equal options.
1. The silent failure is the actual pain, not the requirement.
A bad category returns
NULL, and the only signal is_doing_it_wrong()— invisible withoutWP_DEBUG. Hard consequence (ability silently doesn't register) behind a dev-only signal. This is a DX bug; fix it independent of the category policy by surfacing which rule failed even withoutWP_DEBUG.2. The two-hook ordering is the sharpest edge.
Requiring categories on
wp_abilities_api_categories_initbefore abilities onwp_abilities_api_initis an implicit ordering contract that fails invisibly. Letwp_register_ability()accept a category and resolve it lazily (or auto-create a minimal one) instead of a hard pre-registration gate.3. Required vs optional — the only real design call.
I lean optional-with-a-catch-all + docs, but name the fallback
uncategorized, notgeneral. A respectable-sounding default becomes a dumping ground;uncategorizedsignals "fix this" and stays an escape hatch, not the default path.Growing default categories (option 1) is worth doing anyway but doesn't solve this — it ignores the plugin that wants its own namespace.
Suggested order: fix observability first, ship the docs, then decide required-vs-optional. The first two stand on their own and make the third much smaller.