This skill should be used when helping users create, edit, or register WordPress Abilities (both server-side PHP and client-side JavaScript), register ability categories, or set up the WordPress...
This skill helps users work with the WordPress Abilities API - a standardized system for registering and discovering distinct units of functionality within WordPress. Use this skill to help users create server-side PHP abilities, client-side JavaScript abilities, register categories, and set up the API as a dependency.
The Abilities API makes WordPress functionality discoverable by AI agents and automation tools through machine-readable schemas, permissions, and validation.
Activate this skill when the user requests:
When this skill activates, determine what the user needs:
Are they creating/editing an ability? → Follow the "Creating Abilities" workflow below
Do they need to set up the API first? → Follow the "Setting Up the API" workflow below
Are they just learning about the API?
→ Reference the documentation in references/ and explain concepts
The skill includes a scripts/scaffold-ability.php script designed for programmatic ability generation. Use this when creating abilities to quickly generate validated boilerplate code.
php scripts/scaffold-ability.php \
--name="plugin/ability-name" \
--type="server" \
--category="data-retrieval" \
--label="Optional Label" \
--description="Optional description"
Required Arguments:
--name - Ability name in format "namespace/ability-name"--type - Either "server" (PHP) or "client" (JavaScript)--category - Category slug (e.g., "data-retrieval", "data-modification")Optional Arguments:
--label - Human-readable label (auto-generated from name if omitted)--description - Detailed description (placeholder if omitted)--readonly - "true" or "false" (default: false)--destructive - "true" or "false" (default: true)--idempotent - "true" or "false" (default: false)Output: Complete ability code printed to stdout, ready to be written to plugin files.
Use the scaffold script after gathering requirements from the user (Steps 1-3 of the workflow below). The script generates clean, validated boilerplate that follows best practices.
Important: Always gather required information from the user BEFORE calling the script, or generate sensible defaults based on context.
When helping users create or edit abilities, follow this conversational workflow:
Ask clarifying questions to understand what the ability should do:
Ask where the ability code should live:
wordpress-plugin-scaffold skillAbilities must belong to a category. Ask:
data-retrieval, data-modification, communication, ecommerce, user-managementscripts/scaffold-category.php to generate it:php scripts/scaffold-category.php \
--name="custom-category" \
--label="Custom Category" \
--description="Description of what abilities belong here" \
--type="server|client"
assets/category-template.phpreferences/7.registering-categories.md for detailed category registration informationUse the scaffold script to generate complete, validated code:
php scripts/scaffold-ability.php \
--name="namespace/ability-name" \
--type="server|client" \
--category="category-slug" \
--label="Human Label" \
--description="Detailed description" \
--readonly="true|false" \
--destructive="true|false" \
--idempotent="true|false"
For server-side (PHP): Outputs complete PHP code with callback and registration functions For client-side (JavaScript): Outputs complete JavaScript code with async callback
Alternatively, manually copy and customize templates from assets/ directory:
server-ability-template.php - PHP abilitiesclient-ability-template.js - JavaScript abilitiesReplace all {{PLACEHOLDERS}} with actual values. See templates for full list of placeholders.
Before adding the code to plugin files, validate it using the appropriate validation script:
For PHP abilities:
php scripts/validate-ability.php path/to/ability-file.php
For JavaScript abilities:
node scripts/validate-ability.js path/to/ability-file.js
For PHP categories:
php scripts/validate-category.php path/to/category-file.php
For JavaScript categories:
node scripts/validate-category.js path/to/category-file.js
All validators check:
Exit codes:
0 - Validation passed1 - Validation failed (errors found)2 - File not found or invalid usageFix any errors reported by the validator before proceeding.
Write the validated code to the appropriate plugin files:
includes/abilities.php file and hook into abilities_api_init@wordpress/abilities dependencyabilities_api_categories_init hook before abilitiesUse the Write tool to add the code to the correct location in the plugin.
After code is added to plugin files, suggest testing approaches:
Server-side (PHP):
wp_get_ability('namespace/name') to verify registrationPOST /wp-json/abilities/v1/abilities/{namespace}/{ability-name}/execute$ability->execute( $input_data )Client-side (JavaScript):
wp.data.select('core/abilities').getAbility('namespace/ability-name')wp.data.dispatch('core/abilities').executeAbility('namespace/ability-name', inputData)wp.data.select('core/abilities').getAbilities()The WordPress Abilities API must be available before abilities can be registered. Help users set up the API based on their WordPress version:
WordPress 6.9+: The Abilities API is included in core - no setup needed!
WordPress < 6.9: The API must be installed as a plugin or dependency.
Reference references/2.getting-started.md for detailed setup instructions. Guide users through the most appropriate method:
If they're using wp-env (check for .wp-env.json), help them add it via the wp-env skill:
{
"plugins": ["WordPress/abilities-api"]
}
If they're using WP-CLI:
wp plugin install https://github.com/WordPress/abilities-api/releases/latest/download/abilities-api.zip
wp plugin activate abilities-api
Help them add to their plugin header:
/**
* Plugin Name: My Plugin
* Requires Plugins: abilities-api
*/
Then add availability check:
if ( ! class_exists( 'WP_Ability' ) ) {
add_action( 'admin_notices', function() {
wp_admin_notice(
__( 'This plugin requires the Abilities API. Please install and activate it.', 'my-plugin' ),
'error'
);
} );
return;
}
composer require wordpress/abilities-api
Help users verify the API is loaded:
if ( class_exists( 'WP_Ability' ) ) {
// API is available
echo 'Abilities API version: ' . WP_ABILITIES_API_VERSION;
}
This skill works well with:
The references/ directory contains complete API documentation:
wp_register_ability() with all parameters and examplesWhen to read references:
3.registering-abilities.md2.getting-started.md7.javascript-client.md7.registering-categories.md1.intro.mdscripts/)The skill includes automation scripts for generating and validating both abilities and categories:
scaffold-ability.php: Programmatically generate ability code from CLI arguments
php scripts/scaffold-ability.php --name="plugin/ability" --type="server" --category="data-retrieval"validate-ability.php: Validate PHP ability code independently of WordPress
php scripts/validate-ability.php path/to/ability-file.phpvalidate-ability.js: Validate JavaScript ability registration code
npm install acorn)node scripts/validate-ability.js path/to/ability-file.jsscaffold-category.php: Programmatically generate category registration code
php scripts/scaffold-category.php --name="category-slug" --label="Label" --description="Description" --type="server"validate-category.php: Validate PHP category registration code
token_get_all() for accurate parsingphp scripts/validate-category.php path/to/category-file.phpvalidate-category.js: Validate JavaScript category registration code
npm install acorn)node scripts/validate-category.js path/to/category-file.jsassets/)The skill also includes manual starter templates:
Note: Templates use {{PLACEHOLDER}} syntax and are read by scaffold scripts. You can also manually copy and replace placeholders for custom needs. Scaffold scripts generate code by loading these templates and replacing placeholders with actual values.
When helping users create abilities:
my-plugin/get-user-analytics not my-plugin/analytics__return_true for sensitive operationsreadonly: true for data retrieval abilitiesdestructive: false for abilities that only add/update (never delete)idempotent: true for abilities that can be called repeatedly safelyWP_Error objects with clear error messages'meta' => array(
'annotations' => array(
'readonly' => true,
'destructive' => false,
'idempotent' => true,
),
)
'meta' => array(
'annotations' => array(
'readonly' => false,
'destructive' => false,
'idempotent' => false,
),
)
'meta' => array(
'annotations' => array(
'readonly' => false,
'destructive' => true,
'idempotent' => false,
),
),
'permission_callback' => function() {
return current_user_can( 'manage_options' );
}
When registering client-side abilities with custom categories, use registerAbilityCategory() before registering the ability:
import { registerAbilityCategory, registerAbility } from '@wordpress/abilities';
// Register the category first
await registerAbilityCategory('my-custom-category', {
label: 'My Custom Category',
description: 'Description of what abilities belong in this category',
meta: {
icon: 'dashicons-admin-customizer',
priority: 10,
},
});
// Then register abilities using that category
await registerAbility({
name: 'my-plugin/my-ability',
category: 'my-custom-category', // Uses the client-registered category
// ... other properties
});
For advanced use cases requiring custom behavior, specify a custom class that extends WP_Ability using the ability_class parameter:
class Custom_Ability extends WP_Ability {
// Override methods for custom behavior
public function execute( $input = array() ) {
// Custom execution logic
return parent::execute( $input );
}
}
wp_register_ability( 'my-plugin/custom-ability', array(
// ... standard parameters
'ability_class' => Custom_Ability::class, // Use custom class instead of WP_Ability
) );
Note: This is an advanced feature. Most abilities should use the default WP_Ability class.