-
Notifications
You must be signed in to change notification settings - Fork 14
Propose filters to use with the registered ability #37
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
base: trunk
Are you sure you want to change the base?
Conversation
80c0d3f
to
7dca275
Compare
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.
Pull Request Overview
This PR introduces filter support for the WP_Ability class, allowing developers to customize ability behavior through WordPress hook filters. The main purpose is to provide extensibility points for input/output schemas, permission checks, and execution results.
- Adds four new WordPress filters:
ability_input_schema
,ability_output_schema
,ability_permission_result
, andability_execute_result
- Includes comprehensive test coverage for all filter integration scenarios
- Updates phpcs configuration to accommodate the new hook prefixes
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
includes/abilities-api/class-wp-ability.php | Implements filter integration in schema getters, permission checks, and execution methods |
tests/unit/abilities-api/wpAbilityFilters.php | Adds comprehensive test suite for all filter functionality |
phpcs.xml.dist | Updates coding standards configuration to allow new hook prefixes |
includes/abilities-api.php | Adds phpcs disable comment for global naming conventions |
tests/bootstrap.php | Removes unnecessary phpcs disable comment |
tests/unit/rest-api/*.php | Adds descriptive comments to test files |
tests/unit/abilities-api/wpAbilitiesRegistry.php | Adds descriptive comment to test file |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@jonathanbossenger, this is something to keep on the radar for inclusion in the docs in case we agree that this level of extensibility is expected. |
@gziolo is there an expectation for people to be calling public WP_Ability methods more than once per lifecycle? My two concerns are
|
That's the reality in the WordPress land:
Some recent examples:
There are different audiences here:
If the author of the ability uses a custom class that extends |
@gziolo my question wasn't critique, I was looking for some direction for code review 🙇 I don't think we disagree in premise. The nuance here is our extremely short timetable before merging. To use your example of
Just because we don't have time to evolve it holistically doesn't mean that we can't design our initial API with intention and around specific use cases. And if we don't want to wait to merge these until we have a specific use case from e.g. MCP Adapter or AI Experiments, then we should at least take a bit here to consider the use cases/ code flows for these proposed hooks (instead of designing code to conform with non-rubberducked hooks after the fact). So with that context, and putting yourself into the mind of an "implementer" for a minute - how do you envision these hooks to be used?
|
I'm mostly concerned with this proposal about making it possible to customize the abilities that will get registered through WordPress Core.
Can you provide a real-life example of how often you anticipate the same hooks being called multiple times? In the frontend context, WordPress core won't even process individual abilities because they are never consumed by default, so only the Inside REST API context, they should be called once per ability, depending on the endpoint type:
WP Admin is less predictable at this point, as we don't know how wide the usage will become. That said, WP hooks are everywhere in the codebase. I would be surprised learning that the abilities registry would have a larger impact than the rest of the codebase. What's the part that worries you the most? |
The one that prompted my question is add_filter( 'ability_permission_result', static function( $result ) {
if ( $result instanceof \WP_Error ) {
return $result;
}
return MyCustom::check_user_permissions_in_enterprise_sso( wp_get_current_user() );
}
...
add_filter( 'ability_execute_result', static function ( $result, string $ability_name, array $input ) {
if ( 'my/complex-tool-with-state-and-context' !== $ability_name ) {
return $result;
}
$prev_ability = wp_get_ability( $input['prevAbilityId'] );
if ( $prev_ability->has_permissions() ) {
...
}
}
Solely the timeline to core merge has us theorycrafting these, nothing blocking. The combination of (a.) |
All valid concerns. We don’t have to rush introducing these filters, and wait for feedback from folks what’s limiting them. Aside, caching and filters is often incompatible in WordPress reality because there are two primary challenges:
|
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
8c93454
to
614aae6
Compare
Closes #39.
This PR introduces filter support for the
WP_Ability
class, allowing developers to customize ability behavior through WordPress hook filters. The main purpose is to provide extensibility points for input/output schemas, permission checks, and execution results.ability_input_schema
,ability_output_schema
,ability_permission_result
, andability_execute_result
.Example for how to revoke access to the ability:
Example for how to change the output value:
Testing instructions
6 new unit tests were added to cover possible scenarios. You can run them with
npm run test:php