Development

Securing Your Own Abilities: The Abilities API Changes in WordPress 7.2

· 8 min read
A row of five arched green doors, each with a shield-shaped lock; a friendly robot holds a keycard up to the middle door’s lock, which glows, while the door at the far right stands open with no lock

WordPress 7.2, due December 8, gives AI agents their first real look inside a site. Three new core abilities let any integration with the right permissions read your content, your users and your settings. The release also changes how plugins register their own abilities, and those changes are mostly about security: who can run an ability, and what input actually reaches your code. If you write plugins, or run a site where plugins register abilities, this is the part of 7.2 to understand. An ability is an API endpoint with a friendlier name, and it needs the same care.

Abilities in one minute

The Abilities API arrived in WordPress 6.9. An ability is a named action, like my-plugin/get-post-title, with an input schema, an output schema, a permission check and a function that does the work. Once registered, it can be called three ways:

  • from PHP, with wp_get_ability( 'name' )->execute( $input )
  • over REST, at /wp-json/wp-abilities/v1/abilities/<name>/run, if the ability opts in with show_in_rest
  • by an AI model, as a tool, through the WordPress AI Client

Every path runs the same permission check. That check is the only thing between a caller and your code.

What 7.2 adds

Three read-only core abilities. core/content-query lists posts and pages, core/users-query lists users, and core/settings-get returns site settings (it requires manage_options). They follow the current user’s permissions: raw content only comes back for posts the user can edit, and emails and roles only for users they can edit. Custom post types and plugin settings stay hidden unless they opt in with a new show_in_abilities argument, which defaults to false and isn’t inherited from public or show_in_rest.

Required capabilities. A new required_capabilities argument lists capabilities that every call needs. WordPress checks them with current_user_can() before your permission callback runs. If the list covers everything, you can leave out the callback entirely.

Input is prepared before your code sees it. In 7.2, input is validated against the ability’s schema and then sanitized, on both the PHP and REST paths, before the permission callback runs. If sanitizing fails, the call stops with an error. Before 7.2, a failed field could fall back to the raw input. The core note gives the example: a permission callback receiving the string "false", which PHP treats as true.

Who can see your abilities

This is the part most plugin authors will miss. I checked it in the 7.2 RC3 code. The REST endpoint that lists abilities, GET /wp-json/wp-abilities/v1/abilities, only requires the read capability. Every logged-in user has that, subscribers and customers included. Any ability with show_in_rest turned on is visible to all of them, along with its description and input schema. Whether they can run it is up to your permission check.

show_in_rest defaults to false, so an ability stays PHP-only unless you turn it on. Turn it on only when something outside PHP needs to call it.

Registering an ability the safe way

Here’s a read-only ability that tells people who can edit a post how many revisions it has:

add_action( 'wp_abilities_api_init', static function () {
    wp_register_ability( 'my-plugin/get-revision-count', array(
        'label'       => __( 'Get revision count', 'my-plugin' ),
        'description' => __( 'Count the revisions of a post you can edit.', 'my-plugin' ),
        'category'    => 'my-plugin',

        // Needed for every call. Checked first.
        'required_capabilities' => array( 'edit_posts' ),

        // Depends on the input: can this user edit THIS post?
        'permission_callback' => static function ( int $post_id ): bool {
            return current_user_can( 'edit_post', $post_id );
        },

        'input_schema'  => array( 'type' => 'integer', 'minimum' => 1 ),
        'output_schema' => array( 'type' => 'integer' ),

        'execute_callback' => static function ( int $post_id ): int {
            return count( wp_get_post_revisions( $post_id, array( 'fields' => 'ids' ) ) );
        },

        'meta' => array(
            'show_in_rest' => true,
            'annotations'  => array( 'readonly' => true ),
        ),
    ) );
} );

What makes it safe:

  • Two layers of permission. edit_posts is true for every call, so it goes in required_capabilities. Whether the user can edit this post depends on the input, so that goes in the callback. A capability check alone would let any author read any post’s data.
  • A tight input schema. integer with a minimum of 1 means the callback only ever gets a positive integer. In 7.2 that’s guaranteed, because input is prepared before the permission check.
  • A narrow output. It returns a number, not the revisions. Return what the caller needs and nothing more. An AI model will happily pass on anything you hand it.
  • An honest annotation. More on that below.

Mistakes that expose data

1. __return_true on anything private

Core’s note says to use it “only when the ability is intentionally executable by everyone.” With show_in_rest on, that means anyone, logged in or not. If the ability returns anything you wouldn’t put on the home page, it needs a real check.

2. Checking the capability but not the object

current_user_can( 'edit_posts' ) answers “can this user edit posts in general?” Not “can they edit post 42?” That’s the most common access-control bug in WordPress plugins, and abilities make it easy to repeat. If the input names a post, user, order or entry, check that specific object, with edit_post, edit_user and so on.

3. Treating discovery as permission

7.2 adds a filter to list only the abilities whose required capabilities a user has: ?has_required_capabilities=true on REST, or the same argument to wp_get_abilities(). It doesn’t run permission callbacks. An ability with no required capabilities always passes it. It’s for building menus, not for security. The permission check at execution is the only one that counts.

4. A dishonest readonly annotation

Annotations are hints, but they change how the REST endpoint behaves. In the RC3 run controller, a readonly ability must be called with GET, and its input travels in the query string (?input=...). Query strings end up in server logs, proxy logs and browser history. Two rules follow:

  • Never mark an ability that changes anything as readonly. Tools and models that trust the hint will call it freely.
  • Never mark an ability readonly if its input is sensitive, such as a token or personal data. Use POST, where input goes in the body.

5. Exposing settings that hold secrets

show_in_abilities => true on a setting makes it readable through core/settings-get by anyone with manage_options, and by any AI tool acting on their behalf. Core’s note says it directly: don’t enable it for settings that store secrets, like API keys. An admin can already see them, but there’s no reason to make them one tool call away for a model.

6. Calling check_permissions() with raw input

If your integration checks permission before calling execute(), prepare the input first, or the callback sees something different from what execute() would give it:

$ability = wp_get_ability( 'my-plugin/get-revision-count' );
$input   = $ability->prepare_input( $raw_input );
if ( is_wp_error( $input ) ) {
    return $input;
}
if ( true !== $ability->check_permissions( $input ) ) {
    return new WP_Error( 'forbidden', 'Not allowed.' );
}

Or skip the separate check and call execute(), which does both.

List what a site exposes

To see every registered ability, whether it’s on REST, what it declares, and whether it claims to be read-only:

wp eval 'foreach ( wp_get_abilities() as $a ) {
    printf( "%-45s rest=%-3s readonly=%-3s caps=%s\n",
        $a->get_name(),
        $a->get_meta_item( "show_in_rest" ) ? "yes" : "no",
        ! empty( $a->get_meta_item( "annotations" )["readonly"] ) ? "yes" : "no",
        implode( ",", $a->get_required_capabilities() ) ?: "-" );
}'

Then log in as a subscriber and request /wp-json/wp-abilities/v1/abilities to see what your lowest-privilege users can discover. For every ability with rest=yes and caps=-, read its permission callback. Those are the ones relying entirely on the plugin author getting it right.

Supporting older versions

Leaving out permission_callback in favor of required_capabilities only works on 7.2. A plugin that supports 6.9 to 7.1 should keep its permission callback, and check capabilities inside it. Also watch the type changes: in 7.2, a number schema turns 10 into 10.0 on direct PHP calls, and "false" becomes a real false. Callbacks that used is_int() or strict comparisons need a look.

The bigger lesson

Abilities exist so that software, including AI agents, can act inside WordPress on someone’s behalf. Core is careful: the new abilities are read-only, private post types and settings stay hidden by default, and the model only sees what the current user can see. Write abilities are coming in 7.3. When they arrive, a weak permission callback won’t just leak data. It will let a model change it, at machine speed, for any user who can reach it. Get the habits right now while the stakes are lower: check the object, not just the capability; return the minimum; label honestly. Every ability you register is a new front door. It has to earn its place like everything else.

Sources