The Abilities API (added to WordPress core in 6.9) is a central list of “things your site can do”. Each item, called an ability, has a name, a description, a strict definition of what it accepts and returns, and a permission check. Because everything is described in a standard way, other code, the REST API and AI agents can discover and run abilities without guessing how your plugin works.
In this article you will build one small ability, run it from PHP and from REST, see what happens when something goes wrong, and learn how to expose it to AI agents safely. You only need basic PHP and WordPress knowledge. I ran every example on a clean WordPress 7.1 install.
What problem does the Abilities API solve?
Imagine a restaurant with no menu. Every waiter explains dishes in his own words, and you only find out what is possible by asking around. That is how WordPress plugins worked until now. A plugin could send emails, export orders or clear a cache, but the only way to learn that was reading its code or documentation. Every plugin had its own function names, its own arguments and its own permission rules.
The Abilities API is the menu. Each dish (ability) is listed in one place with:
- a name and a human-readable description;
- what you must give it (the input);
- what you get back (the output);
- who is allowed to order it.
For developers this means one predictable way to call functionality. For AI agents it is even more important: an agent cannot read your PHP, but it can read a clear, machine-readable menu.
What an ability is made of
| Part | What it is | Example |
|---|---|---|
| Name | Unique ID in the format namespace/ability-name. Only lowercase letters, numbers, dashes and slashes. | demo/get-latest-posts |
| Category | A group for abilities. It must be registered before the ability that uses it. | content-tools |
| Input schema | A JSON Schema that describes what the ability accepts. WordPress validates the input for you. | count is an integer from 1 to 10 |
| Output schema | A JSON Schema that describes what comes back. | a list of posts with id, title, url |
| Callbacks | execute_callback does the work. permission_callback decides who may run it. | your PHP functions |
JSON Schema sounds scary, but here it is just a PHP array that says “this must be an integer, between 1 and 10”.
Register your first ability
We will build demo/get-latest-posts: it returns the newest published posts. It only reads data, so it is a safe first example.
Put this code in a small plugin or in your theme’s functions.php. Two things matter a lot:
- A category must be registered on the
wp_abilities_api_categories_inithook. - An ability must be registered on the
wp_abilities_api_inithook. If you register it anywhere else, WordPress shows a “doing it wrong” notice and the ability is not registered.
<?php
// 1. Register a category.
add_action( 'wp_abilities_api_categories_init', function () {
wp_register_ability_category(
'content-tools',
array(
'label' => __( 'Content tools', 'demo' ),
'description' => __( 'Abilities that read content on this site.', 'demo' ),
)
);
} );
// 2. Register the ability.
add_action( 'wp_abilities_api_init', function () {
wp_register_ability(
'demo/get-latest-posts',
array(
'label' => __( 'Get latest posts', 'demo' ),
'description' => __( 'Returns the newest published posts: id, title and URL.', 'demo' ),
'category' => 'content-tools',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'count' => array(
'type' => 'integer',
'description' => 'How many posts to return (1-10).',
'minimum' => 1,
'maximum' => 10,
'default' => 3,
),
),
'additionalProperties' => false,
'default' => array(),
),
'output_schema' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'id' => array( 'type' => 'integer' ),
'title' => array( 'type' => 'string' ),
'url' => array( 'type' => 'string' ),
),
),
),
'execute_callback' => 'demo_get_latest_posts',
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
'meta' => array(
'show_in_rest' => true,
'annotations' => array(
'readonly' => true,
),
),
)
);
} );
// 3. The function that does the work.
function demo_get_latest_posts( $input ) {
$count = isset( $input['count'] ) ? (int) $input['count'] : 3;
$posts = get_posts(
array(
'numberposts' => $count,
'post_status' => 'publish',
)
);
return array_map(
function ( $post ) {
return array(
'id' => $post->ID,
'title' => get_the_title( $post ),
'url' => get_permalink( $post ),
);
},
$posts
);
}
Let’s read the important lines:
input_schemadescribes the input.'additionalProperties' => falsemeans “reject any field I did not list”. The root-level'default' => array()lets callers run the ability with no input at all (more on this in the mistakes section).permission_callbackreturnstrueorfalse. Here only users who can edit posts may run it.execute_callbackreceives the already validated input. You do not need to check thatcountis an integer between 1 and 10, because WordPress has done it before your function runs.show_in_rest => truemakes the ability available through the REST API. Without it, the ability exists but REST cannot see it.annotations => readonlytells tools “this ability does not change anything”. It also affects which HTTP method REST uses (see below).
Run an ability from PHP
$ability = wp_get_ability( 'demo/get-latest-posts' );
$result = $ability->execute( array( 'count' => 2 ) );
if ( is_wp_error( $result ) ) {
// Something went wrong: wrong input, no permission, etc.
error_log( $result->get_error_message() );
} else {
// $result is an array of posts.
}
execute() returns either the result or a WP_Error, so always check it with is_wp_error(). On my test site this returned:
[{"id":5,"title":"Second post","url":"http://127.0.0.1:8899/?p=5"},
{"id":1,"title":"Hello world!","url":"http://127.0.0.1:8899/?p=1"}]
Run an ability through the REST API
Because we set show_in_rest, WordPress exposes these endpoints under /wp-json/wp-abilities/v1/:
GET /abilities: list all abilities;GET /abilities/{name}: details of one ability;/abilities/{name}/run: run it.
Which HTTP method? It depends on the annotations:
| Ability type | Method |
|---|---|
readonly is true | GET |
| changes data (default) | POST |
| destructive and idempotent | DELETE |
Our ability is read-only, so we call it with GET. The input goes into the query string:
curl -u "username:APPLICATION_PASSWORD" \
"https://example.com/wp-json/wp-abilities/v1/abilities/demo/get-latest-posts/run?input[count]=2"
If you use the wrong method, WordPress answers with 405 and a clear message: “Read-only abilities require GET method.” For abilities that change data you send a POST with JSON: {"input": {"count": 2}}.
All endpoints require an authenticated user. For scripts and external tools the recommended way is an Application Password (Users, Profile, Application Passwords). Anonymous calls are rejected with 401.
What happens with bad input or no permission
This is where the schema pays off. I ran the same ability with wrong data on WordPress 7.1:
| Call | Result |
|---|---|
count = 99 | ability_invalid_input: input[count] must be between 1 (inclusive) and 10 (inclusive) |
count = “abc” | ability_invalid_input: input[count] is not of type integer |
unknown field foo | ability_invalid_input: foo is not a valid property of Object |
| not logged in | ability_invalid_permissions: does not have necessary permission (REST: 401) |
Your execute_callback never runs in these cases. You write the rules once, in the schema, and WordPress enforces them for PHP, REST and AI agents alike.
If your own code fails, return a WP_Error from execute_callback and the caller gets a normal error.
Hooks and abilities that already exist
Two actions fire around every execution, which is handy for logging:
add_action( 'wp_before_execute_ability', function ( $name, $input ) {
error_log( "Running {$name}" );
}, 10, 2 );
add_action( 'wp_after_execute_ability', function ( $name, $input, $result ) {
error_log( "Finished {$name}" );
}, 10, 3 );
WordPress also ships with abilities of its own. On a clean 7.1 install wp_get_abilities() returns core/get-site-info, core/get-user-info and core/get-environment-info. For example:
wp_get_ability( 'core/get-site-info' )->execute( array( 'fields' => array( 'name', 'version' ) ) );
// {"name":"Test","version":"7.1"}
Connect abilities to AI agents with the MCP Adapter
MCP (Model Context Protocol) is a standard way for AI apps, such as Claude or Cursor, to use external tools. The official MCP Adapter plugin turns your registered abilities into MCP tools. An agent can then discover your menu and call your abilities.
In short, according to the official MCP Adapter guide:
- Install and activate the MCP Adapter plugin. It creates a default MCP server.
- Mark your ability as public for MCP by adding
'mcp' => array( 'public' => true )to itsmeta. - Connect your AI client over STDIO (needs WP-CLI) or over HTTP with an application password.
I did not test the adapter for this article, so check the adapter’s repository for the current setup, because the code changes between versions. The key idea is the same: an ability you describe well is an ability an agent can use. A clear description and a strict schema are the instructions for the AI.
Security checklist
An AI agent acts as a real WordPress user. Treat every ability like a public door.
- Check capabilities in
permission_callback. Ask for the smallest capability that makes sense (edit_posts,manage_options, and so on). - Never use
__return_truefor abilities that change data. It lets everyone run them. - Use a dedicated user with limited rights for AI and automation, not your administrator account.
- Start with read-only abilities, especially on a live site, and add write abilities later.
- Keep schemas strict. Use
minimum,maximum,enumandadditionalProperties => false. - Log usage with the before and after hooks.
Common beginner mistakes
- Registering on
init. The ability silently does not exist. Usewp_abilities_api_init. WordPress logs: “Abilities must be registered on the wp_abilities_api_init action.” - Registering the category too late or not at all. Register categories on
wp_abilities_api_categories_init, before the abilities that use them. - Running with no input and getting “input is not of type object”. If your schema is an object but has no root-level
default, callingexecute()without arguments fails. Add'default' => array()at the schema root (adefaultinside a single property is not enough). I hit this one while testing. - Forgetting
show_in_rest. The ability works in PHP but REST returns “not found”. - Using POST for a read-only ability. You get
405. Read-only meansGET. - Doing your own validation again. The schema already did it. Keep the callback short.
When to use the Abilities API, and when not to
Use it when you want other code, other plugins or AI agents to discover and run your functionality in a standard way. It is a good fit for actions like “get orders”, “create a draft”, “clear cache”.
Skip it for internal helper functions that nobody else will call, and for simple custom REST routes that only your own front end uses. A normal function or a normal REST route is simpler there.
Frequently asked questions
Which WordPress version has the Abilities API? It was added to core in WordPress 6.9. For older versions, check function_exists( 'wp_register_ability' ) before using it.
Is the Abilities API the same as the REST API? No. Abilities are a registry of actions with input, output and permissions. REST is one way to reach them. You can also run them from PHP or through MCP.
Do I need to know JSON Schema? Only the basics: type, properties, minimum, maximum, default. WordPress supports a subset of JSON Schema.
Is it safe to expose abilities to AI? It is as safe as your permission_callback and your schemas. Start read-only, use a limited user and log calls.
Where do I register abilities? In a plugin (or theme) on the wp_abilities_api_init hook, with categories on wp_abilities_api_categories_init.
Need a custom WordPress plugin or an AI-ready site?
I build custom WordPress themes, Gutenberg blocks and integrations. If you want your site’s features to be ready for automation and AI agents, get in touch.
Read also
- What Is WP-CLI? 10 Essential Commands for WordPress
- WordPress AJAX Tutorial: How admin-ajax.php Works
- How to Secure a WordPress Site: 12 Essential Steps