Skip to content

Conversation

@dkotter
Copy link
Collaborator

@dkotter dkotter commented Sep 10, 2025

Description of the Change

Note

Similar to #994, this is an early test of the new WordPress Abilities API and things will likely change as that matures. Opening this PR both for discussion and as an example of how we may want to implement this.

This PR brings in the WordPress Abilities API as a new composer dependency and integrates that into the Title Generation and Image Generation Features. Within the existing base Feature class, if a Feature is enabled and configured, we hook into the new abilities_api_init hook to register any needed abilities. The thought is that each individual Feature will have their own register_ability method that will be called here.

I set this up in the Title Generation and Image Generation Features, registering the ability, adding a custom permission callback and adding a custom execution callback. All of this is structured very similarly to our existing custom REST endpoint that this Feature uses. I've then updated the front-end handling to use the new Abilities API endpoint instead of our custom endpoints, which required some slight changes to how the data is structured.

Points open to discussion:

  • Should we stick with our custom REST endpoints or use the new Abilities endpoints? My opinion (and what I did here) was to use the new Abilities endpoints. Seems like if we're going to register something as an ability, might as well go all in
  • If we use the new Abilities endpoints, should we remove the existing custom endpoints? I have not done that in this PR though I would suggest we do that (to avoid duplicate code), noting that could be seen as a breaking change
  • Once this gets merged into Core (slated for WP 6.9) should we continue to bundle the package with ClassifAI or set our minimum WordPress version to 6.9?

Next steps:

  • Determine if the approach in this PR is the best way to integrate the Abilities API
  • Integrate the Abilities API into all other Features
  • Remove existing REST endpoints

How to test the Change

  1. Checkout this branch and run composer install and npm run build
  2. Configure the Title Generation Feature
  3. Confirm that this Feature still works as expected
  4. Configure the Image Generation Feature
  5. Confirm that this Feature still works as expected

Changelog Entry

Added - New feature
Changed - Existing functionality
Deprecated - Soon-to-be removed feature
Removed - Feature
Fixed - Bug fix
Security - Vulnerability
Developer - Non-functional update

Credits

Props @dkotter

Checklist:

…ss. This will only register an ability if the feature is enabled and configured and only if the feature has the register_ability method
…_Error's. Fix an issue with the user check failing when run under the abilities API
@dkotter dkotter added this to the Future Release milestone Sep 10, 2025
@dkotter dkotter self-assigned this Sep 10, 2025
@dkotter dkotter requested review from a team and jeffpaul as code owners September 10, 2025 17:48
@github-actions github-actions bot added the needs:code-review This requires code review. label Sep 10, 2025
*/
public function abilities_api_init() {
if ( function_exists( 'wp_register_ability' ) ) {
$this->register_ability();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set this up to match what we already do in this class but wondering if it would be better to have a method_exists check here and remove the empty method below?

],
],
'output_schema' => [
'type' => 'object',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing, seems we need to return an object in order to support any WP_Error's that may return. This does mean we have to change the structure of what we return to be more than just a simple array unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant