The Abilities API is a registry in WordPress core. Each entry, an ability, is one piece of functionality with a contract a machine can read: a name, a description, an input schema, an output schema, a category, a permission callback and an execute callback. Register a feature once, and PHP, the REST API, JavaScript and AI agents can all find it and run it.
This talk is a developer’s walk through registering abilities, and it is mostly code. It replaces a feature wired up twice, once for AJAX and once for REST, with one registration: one permission check, validated input, and no route of your own to maintain. It then shows how the same ability is used from PHP, over REST, from JavaScript and by AI agents through the MCP Adapter.
What the talk covers
- What the Abilities API is, and which WordPress version brought which part: PHP registration and REST routes in 6.9, the JavaScript client in 7.0, refined exposure flags in 7.1.
- The six core concepts: ability, category, registry, callback, schemas and permission callback.
- Before and after: hand-wired AJAX and REST against one registered ability.
- Registering a category and an ability, on the right hooks.
- The arguments, the execute callback, and naming:
namespace/ability-name, lowercase with dashes. - Input and output schemas, with the same validator the REST API uses.
- Permission policies that check the object, not only the role.
- Meta: annotations (readonly, destructive, idempotent) and the flags that expose an ability to REST and MCP. Abilities are private until you opt in.
- Consuming abilities from PHP, REST, JavaScript and AI agents.
- Gotchas: the wrong hook, a category registered too late, underscores in names, strict output schemas and vague descriptions.
Slides
Code from the slides
The example registers one ability, wcgalicia/get-post-summary, which returns the title, excerpt and word count of a post. A category comes first, because it must exist before any ability that refers to it.
add_action(
'wp_abilities_api_categories_init',
function () {
wp_register_ability_category(
'wcgalicia-content',
[
'label' => __( 'WordCamp Content', 'wcgalicia' ),
'description' => __( 'Abilities for WordCamp content.', 'wcgalicia' ),
]
);
}
);
Then the ability itself. The description is not a comment: an AI agent reads it to decide whether this is the right tool.
add_action( 'wp_abilities_api_init', function () {
wp_register_ability( 'wcgalicia/get-post-summary', [
'label' => __( 'Get post summary', 'wcgalicia' ),
'description' => __( 'Returns title, excerpt and word count of a post.', 'wcgalicia' ),
'category' => 'wcgalicia-content',
'input_schema' => [ /* see below */ ],
'output_schema' => [ /* title, excerpt, word_count */ ],
'permission_callback' => fn( $input ) => current_user_can( 'read_post', $input['post_id'] ),
'execute_callback' => 'wcgalicia_get_post_summary',
'meta' => [ 'show_in_rest' => true ],
] );
} );
The input schema. Describe every property; it is free documentation for agents.
'input_schema' => [
'type' => 'object',
'properties' => [
'post_id' => [
'type' => 'integer',
'minimum' => 1,
'description' => 'ID of the post to summarize.',
],
'length' => [
'type' => 'string',
'enum' => [ 'short', 'long' ],
'default' => 'short',
],
],
'required' => [ 'post_id' ],
'additionalProperties' => false,
],
The execute callback takes one argument and returns one result. The input arrives already validated, and there is no echo, no wp_die, no $_POST and no nonce handling. The same function serves a PHP call, a REST request, a JavaScript call and an MCP tool call.
function wcgalicia_get_post_summary( array $input ) {
$post = get_post( $input['post_id'] );
if ( ! $post ) {
return new WP_Error(
'not_found',
__( 'Post not found.', 'wcgalicia' ),
[ 'status' => 404 ]
);
}
return [
'title' => $post->post_title,
'excerpt' => get_the_excerpt( $post ),
'word_count' => str_word_count(
wp_strip_all_tags( $post->post_content )
),
];
}
Over REST there are three endpoints and no register_rest_route() call. A read-only ability runs with GET, and its input goes in the query string.
GET /wp-json/wp-abilities/v1/abilities
GET /wp-json/wp-abilities/v1/abilities/wcgalicia/get-post-summary
GET /wp-json/wp-abilities/v1/abilities/wcgalicia/get-post-summary/run?input[post_id]=42&input[length]=short
Takeaways
- Start with two or three read-only abilities from your plugin.
- Write descriptions like documentation, and add annotations.
- Opt in to REST and MCP deliberately, not by default.