WordPress 6.9 introduced the Abilities API An API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. with three abilities that return information about the site, the current user, and the environment. In WordPress 7.2 we continued that work and added three abilities that read content, users, and settings:
These abilities expand the baseline of site functionality made available through the Abilities API, which is part of the plan to make WordPress ready for agents, described in WordPress for the Agentic Web. Additional read & write abilities are planned for future releases, but let’s take a look at how developers can interact with this trio of read-only abilities in WordPress 7.2.
Querying content and users
core/content-query and core/users-query take the same input: where has the filters, fields the fields to return, and pagination the page and per_page.
$result = wp_get_ability( 'core/content-query' )->execute(
array(
'where' => array(
'type' => 'post',
'status' => array( 'draft' ),
),
'fields' => array( 'title', 'date', 'author' ),
)
);
$result is a WP_Error if the input is not valid or the user cannot run the query. Otherwise it has the items and the totals:
{
"items": [
{
"id": 123,
"date": { "site": "2026-10-21T09:30:00+01:00", "gmt": "2026-10-21T08:30:00+00:00" },
"title": { "raw": "Launch notes", "rendered": "Launch notes" },
"author": { "id": 42, "name": "Maya Carter", "slug": "mcarter" }
}
],
"pagination": { "total": 1, "total_pages": 1 }
}
Some details:
- For content,
where.type is required. The other filters are ids, slugs, status, author, and parent. Users can be filtered by ids, slugs, usernames, roles, and has_published_posts.
- Filters are exact matches, there is no text search.
- Without
status, only published posts are returned, unless the query lists ids or slugs.
fields is optional and a few fields are returned by default. id is always included.
per_page is 10 by default and can go up to 100.
- Some fields depend on the user. The
raw title, excerpt An excerpt is the description of the blog post or page that will by default show on the blog archive page, in search results (SERPs), and on social media. With an SEO plugin, the excerpt may also be in that plugin’s metabox., and content are only returned for posts the user can edit. Fields like email and roles are only returned for the user’s own account and for users they can edit.
Reading settings
core/settings-get returns the settings as name and value pairs, and requires the manage_options capability A capability is permission to perform one or more types of task. Checking if a user has a capability is performed by the current_user_can function. Each user of a WordPress site might have some permissions but not others, depending on their role. For example, users who have the Author role usually have permission to edit their own posts (the “edit_posts” capability), but not permission to edit other users’ posts (the “edit_others_posts” capability).. fields asks for specific settings and group for the settings of a group (general, writing, reading, or discussion). With no input, all the exposed settings are returned.
$settings = wp_get_ability( 'core/settings-get' )->execute(
array( 'fields' => array( 'title', 'timezone' ) )
);
// array( 'title' => 'Acme Robotics', 'timezone' => 'Europe/Lisbon' )
Exposing your own post types and settings
By default only posts, pages, and a set of core Core is the set of software required to run WordPress. The Core Development Team builds WordPress. settings (site title, timezone, posts per page, and so on) are exposed. Custom post types and plugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party. settings need to opt in with the new show_in_abilities argument added to register_post_type() and register_setting() in WordPress 7.2:
add_action(
'init',
static function () {
register_post_type(
'book',
array(
'label' => __( 'Books', 'my-plugin' ),
'public' => true,
'show_in_abilities' => true,
)
);
register_setting(
'my_plugin',
'my_plugin_items_per_page',
array(
'type' => 'integer',
'default' => 12,
'show_in_abilities' => true,
)
);
}
);
show_in_abilities is false by default and has to be set explicitly. It is not inherited from public or show_in_rest. For post types it is a boolean. For settings it can be true, which uses the name and schema from show_in_rest when they exist, or an array with its own name and schema.
The exposed post types and settings are read when the abilities are registered, so register them on init. A setting that is only registered on admin_init or rest_api_init may not be available.
Don’t enable show_in_abilities for settings that store secrets, like API keys.
Calling the abilities from JavaScript JavaScript or JS is an object-oriented computer programming language commonly used to create interactive effects within web browsers. WordPress makes extensive use of JS for a better user experience. While PHP is executed on the server, JS executes within a user’s browser.
https://www.javascript.com
On the client the abilities run with executeAbility, once @wordpress/core-abilities has loaded them from the server:
import { ready } from '@wordpress/core-abilities';
import { executeAbility } from '@wordpress/abilities';
await ready;
const { items } = await executeAbility( 'core/users-query', {
where: { roles: [ 'editor' ] },
fields: [ 'name', 'slug' ],
} );
// [ { id: 42, name: 'Maya Carter', slug: 'mcarter' } ]
The script module depends on both @wordpress/abilities to provide client-side Abilities API infrastructure plus @wordpress/core-abilities to provide the abilities themselves. The call is a GET request to /wp-abilities/v1/abilities/core/users-query/run, so the REST API The REST API is an acronym for the RESTful Application Program Interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. It is how the front end of an application (think “phone app” or “website”) can communicate with the data store (think “database” or “file system”)
https://developer.wordpress.org/rest-api/ can also be used directly. The Client-Side Abilities API dev note has more details.
Using the abilities with the AI Client
The using_abilities() method on the AI Client’s Prompt Builder passes the abilities to a model as tools. The function below uses them to answer questions about the site. The loop The Loop is PHP code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post. https://codex.wordpress.org/The_Loop runs while the model keeps asking for abilities, which we run with WP_AI_Client_Ability_Function_Resolver. When it stops asking, the result has the answer.
use WordPress\AiClient\Messages\DTO\MessagePart;
use WordPress\AiClient\Messages\DTO\UserMessage;
function my_plugin_ask_site( string $question ) {
$abilities = array( 'core/content-query', 'core/users-query', 'core/settings-get' );
$resolver = new WP_AI_Client_Ability_Function_Resolver( ...$abilities );
$messages = array( new UserMessage( array( new MessagePart( $question ) ) ) );
do {
$result = wp_ai_client_prompt( $messages )
->using_system_instruction( 'Answer questions about this site using the abilities.' )
->using_abilities( ...$abilities )
->generate_text_result();
if ( is_wp_error( $result ) ) {
return $result;
}
// Run the abilities the model asked for and add the results to the conversation.
$ran_abilities = false;
foreach ( $result->toMessages() as $message ) {
$messages[] = $message;
if ( $resolver->has_ability_calls( $message ) ) {
$messages[] = $resolver->execute_abilities( $message );
$ran_abilities = true;
}
}
} while ( $ran_abilities );
return $result->toText();
}
$answer = my_plugin_ask_site( 'What is the timezone of this site, and who wrote the latest post?' );
The example above leverages the AI provider configured in Settings > Connectors, and the model only gets the data the current user can see. This loop runs until the model stops asking for abilities, but in production code you’ll also want to limit how many times the loop can run.
What’s next
More abilities are being worked on for WordPress 7.3. This tracking issue in the new WordPress/abilities repo is the place to follow that work and to help. The proposed list of abilities to be added next and their shapes can be found in this pull request.
Props to @gziolo, @justlevine, and @nikskyverge for reviewing and providing feedback on this post.
#7-2, #dev-notes, #dev-notes-7-2
You must be logged in to post a comment.