{"id":1219,"date":"2026-02-12T12:00:54","date_gmt":"2026-02-12T13:00:54","guid":{"rendered":"https:\/\/computercoursesonline.com\/?p=1219"},"modified":"2026-04-30T21:16:00","modified_gmt":"2026-04-30T21:16:00","slug":"how-to-use-the-wordpress-abilities-api-register-execute","status":"publish","type":"post","link":"https:\/\/computercoursesonline.com\/index.php\/2026\/02\/12\/how-to-use-the-wordpress-abilities-api-register-execute\/","title":{"rendered":"How to Use the WordPress Abilities API (Register & Execute)"},"content":{"rendered":"
WordPress 6.9 is shipped with a number of interesting features. Among these is a new API called Abilities API<\/a><\/strong>.<\/p>\n The Abilities API<\/strong> provides a standardized way for WordPress core, plugins, and themes to define their capabilities in a format both humans and machines can read.<\/p>\n In this post, we\u2019ll explore what the Abilities API is, why it matters, and how to use it in practice with some code examples.<\/p>\n Without further ado, let\u2019s get started.<\/p>\n The Abilities API is a new feature in WordPress that acts like a dictionary of everything a site can do. Before this, there was no simple or consistent way for plugins or external tools to discover a site\u2019s available features. Functionality was often scattered across hooks, REST API endpoints, and various pieces of custom code.<\/p>\n With the Abilities API, automation tools, AI assistants, and other plugins can more easily understand how to interact with a WordPress site. Tools like AI agents, Zapier, or n8n<\/a> can simply ask WordPress, \u201cWhat can you do?\u201d<\/strong> and receive a structured list of abilities.<\/p>\n This API also makes cross-plugin collaboration much cleaner. Plugins can call each other\u2019s abilities directly instead of relying on hidden hooks or fragile workarounds.<\/p>\n To use the Abilities API<\/strong>, the first step is to register a new ability. This is typically done within your plugin or theme. An \u201cAbility\u201d should contain:<\/p>\n Here is a simple example of how we register an ability that analyzes a site and returns some metrics.<\/p>\n In this example, we call it Here is another example of registering an ability that processes an order. This ability takes in customer ID, product SKUs, and a payment token as input, and returns the order ID, status, and a confirmation message as output.<\/p>\n Registering an ability doesn\u2019t do much on its own. We also want to execute it and get the result.<\/p>\n In PHP, using an ability is straightforward. WordPress provides a function Here\u2019s how you might execute the If the ability requires inputs such as in the Notice that we didn\u2019t have to manually handle permission checks or input validation here. If the current user didn\u2019t have permission, or if we passed a wrong type of input, Now that we\u2019ve seen how to declare and use abilities on the back-end, let\u2019s look at how abilities can be accessed from JavaScript, which covers front-end use cases and external integrations.<\/p>\n The Abilities API supports REST API out of the box, but you need to make sure that you enable the Once that\u2019s set, the ability becomes accessible under a special REST namespace This means external applications or your own front-end code can execute abilities by sending HTTP requests without you writing any extra REST handler code. WordPress takes care of that based on the info you provided.<\/p>\n WordPress is also introducing a JavaScript client library for the Abilities API, making it much easier to call abilities from the browser or any headless JS setup. Instead of writing manual First, we\u2019d need to install the library with NPM:<\/p>\n Then, we can use it like this in our JavaScript application:<\/p>\n The Abilities API introduces a new way for WordPress to describe what it can do in a clear and more standardized format. This improves the interoperability of your site and allows it to work more naturally with AI assistants or automation tools.<\/p>\n In this article, we\u2019ve just scratched the surface of what\u2019s possible with the Abilities API. As more plugins and themes adopt it, we can expect a richer ecosystem where capabilities are easily discoverable and usable across different contexts.<\/p>\n And in the next article, we\u2019ll see how we can integrate your WordPress site with external applications like Claude or LM Studio using the Abilities API.<\/p>\n So stay tuned!<\/p>\n The post How to Use the WordPress Abilities API (Register & Execute)<\/a> appeared first on Hongkiat<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" WordPress 6.9 is shipped with a number of interesting features. Among these is a new API called Abilities API. The Abilities API provides a standardized way for WordPress core, plugins, and themes to define their capabilities in a format both humans and machines can read. In this post, we\u2019ll explore what the Abilities API is,…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/posts\/1219"}],"collection":[{"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/comments?post=1219"}],"version-history":[{"count":1,"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/posts\/1219\/revisions"}],"predecessor-version":[{"id":1220,"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/posts\/1219\/revisions\/1220"}],"wp:attachment":[{"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/media?parent=1219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/categories?post=1219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computercoursesonline.com\/index.php\/wp-json\/wp\/v2\/tags?post=1219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}What is Abilities API?<\/h2>\n
Getting Started<\/h2>\n
\n
hongkiatcom\/create-invoice<\/code><\/li>\nhongkiatcom\/site-analytics-summary<\/code>. It doesn\u2019t require any inputs and returns an object containing three metrics: visits, signups, and sales. The ability can only be executed by users with the manage_options<\/code> capability.<\/p>\n\r\nadd_action( 'wp_abilities_api_init', function () {\r\n if ( ! function_exists( 'wp_register_ability' ) ) {\r\n return;\r\n }\r\n \r\n wp_register_ability(\r\n 'hongkiatcom\/site-analytics-summary',\r\n [\r\n 'label' => __( 'Get Site Analytics Summary', 'myplugin' ),\r\n 'description' => __( 'Returns a simple overview of site performance.', 'myplugin' ),\r\n 'input_schema' => [\r\n 'type' => 'object',\r\n 'properties' => [],\r\n ],\r\n 'output_schema' => [\r\n 'type' => 'object',\r\n 'properties' => [\r\n 'visits' => [ 'type' => 'integer' ],\r\n 'signups' => [ 'type' => 'integer' ],\r\n 'sales' => [ 'type' => 'integer' ],\r\n ],\r\n ],\r\n 'permission_callback' => function () {\r\n return current_user_can( 'manage_options' );\r\n },\r\n 'execute_callback' => function () {\r\n return [\r\n 'visits' => 1473,\r\n 'signups' => 32,\r\n 'sales' => 5,\r\n ];\r\n },\r\n ]\r\n );\r\n});\r\n<\/pre>\n\r\nadd_action( 'init', function() {\r\n if ( ! function_exists( 'wp_register_ability' ) ) {\r\n return;\r\n }\r\n\r\n wp_register_ability( 'hongkiatcom\/process-order', [\r\n 'description' => 'Handles payment, creates an order record, and sends a confirmation email.',\r\n 'execute_callback' => function () {\r\n \/\/ Implementation of order processing logic goes here...\r\n },\r\n 'input_schema' => [\r\n 'type' => 'object',\r\n 'properties' => [\r\n 'customer_id' => [\r\n 'type' => 'integer',\r\n 'description' => 'The ID of the customer placing the order.',\r\n ],\r\n 'product_skus' => [\r\n 'type' => 'array',\r\n 'description' => 'An array of product SKUs (strings) to be included in the order.',\r\n 'items' => [ 'type' => 'string' ],\r\n ],\r\n 'payment_token' => [\r\n 'type' => 'string',\r\n 'description' => 'A secure, single-use token from the payment gateway.',\r\n ],\r\n ],\r\n 'required' => [ 'customer_id', 'product_skus', 'payment_token' ],\r\n ],\r\n 'output_schema' => [\r\n 'type' => 'object',\r\n 'properties' => [\r\n 'order_id' => [\r\n 'type' => 'integer',\r\n 'description' => 'The ID of the newly created order post.',\r\n ],\r\n 'order_status' => [\r\n 'type' => 'string',\r\n 'description' => 'The resulting status of the order (e.g., \"processing\", \"pending\").',\r\n ],\r\n 'message' => [\r\n 'type' => 'string',\r\n 'description' => 'A confirmation message.',\r\n ],\r\n ],\r\n ],\r\n ] );\r\n} );\r\n<\/pre>\nExecuting Abilities<\/h2>\n
In PHP<\/h5>\n
wp_get_ability()<\/code> to retrieve the ability object by name, and then you call the ability\u2019s execute()<\/code> method.<\/p>\nsite-analytics-summary<\/code> ability we registered:<\/p>\n\r\n$ability = wp_get_ability( 'hongkiatcom\/site-analytics-summary' );\r\n\r\nif ( $ability ) {\r\n $result = $ability->execute();\r\n}\r\n<\/pre>\nprocess-order<\/code> example, you would pass an associative array of inputs to the execute()<\/code> method:<\/p>\n\r\n$ability = wp_get_ability( 'hongkiatcom\/process-order' );\r\nif ( $ability ) {\r\n $inputs = [\r\n 'customer_id' => 123,\r\n 'product_skus' => [ 'SKU123', 'SKU456' ],\r\n 'payment_token'=> 'tok_1A2B3C****',\r\n ];\r\n $result = $ability->execute( $inputs );\r\n}\r\n<\/pre>\nexecute()<\/code> would fail gracefully. It wouldn\u2019t run the callback and would return an error or false. This is thanks to the schemas and permission callback we set up during registration. It makes using the ability safe and predictable.<\/p>\nIn JavaScript<\/h5>\n
show_in_rest<\/code> on the Ability registration, for example:<\/p>\n\r\nadd_action( 'wp_abilities_api_init', function () {\r\n if ( ! function_exists( 'wp_register_ability' ) ) {\r\n return;\r\n }\r\n \r\n wp_register_ability(\r\n 'hongkiatcom\/site-analytics-summary',\r\n [\r\n ...\r\n 'execute_callback' => function () {\r\n return [\r\n 'visits' => 1473,\r\n 'signups' => 32,\r\n 'sales' => 5,\r\n ];\r\n },\r\n 'meta' => [\r\n 'show_in_rest' => true,\r\n ],\r\n ]\r\n );\r\n});\r\n<\/pre>\nwp-abilities\/v1\/{ability-namespace}\/{ability-name}<\/code>. In our example above, the full REST endpoint to execute the ability would be: \/wp-json\/wp-abilities\/v1\/hongkiatcom\/site-analytics-summary<\/code>.<\/p>\nfetch()<\/code> calls, you can simply use built-in helper functions to list, fetch, and run abilities.<\/p>\n\r\nnpm i @wordpress\/abilities\r\n<\/pre>\n
\r\nuseEffect(() => {\r\n executeAbility( 'hongkiatcom\/site-analytics-summary' ).then( ( response ) => {\r\n setResponse( response ); \/\/ Store the result in state.\r\n } );\r\n}, []);\r\n<\/pre>\nWrapping Up<\/h2>\n