You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1.intro.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# 1. Introduction & Overview
2
2
3
-
**What is the Abilities API?**
3
+
## What is the Abilities API?
4
4
5
5
The WordPress Abilities API provides a standardized way to register and discover distinct units of functionality within a WordPress site. These units, called "Abilities", represent specific actions or capabilities that components can perform, with clearly defined inputs, outputs, and permissions.
6
6
7
7
It acts as a central registry, making it easier for different parts of WordPress, third-party plugins, themes, and external systems (like AI agents) to understand and interact with the capabilities available on a specific site.
8
8
9
-
**Core Concepts**
9
+
## Core Concepts
10
10
11
11
-**Ability:** A distinct piece of functionality with a unique name following the `namespace/ability-name` pattern. Each ability has a human-readable name and description, input/output definitions (using JSON Schema), optional permissions, and an associated callback function for execution. Each registered Ability is an instance of the `WP_Ability` class.
12
12
-**Registry:** A central, singleton object (`WP_Abilities_Registry`) that holds all registered abilities. It provides methods for registering, unregistering, finding, and querying abilities.
@@ -15,7 +15,7 @@ It acts as a central registry, making it easier for different parts of WordPress
15
15
-**Permission Callback:** An optional function that determines if the current user can execute a specific ability.
16
16
-**Namespace:** The first part of an ability name (before the slash), typically matching the plugin or component name that registers the ability.
17
17
18
-
**Goals and Benefits**
18
+
## Goals and Benefits
19
19
20
20
-**Standardization:** Provides a single, consistent way to expose site capabilities.
21
21
-**Discoverability:** Makes functionality easily discoverable by AI systems and automation tools.
@@ -24,15 +24,15 @@ It acts as a central registry, making it easier for different parts of WordPress
24
24
-**Extensibility:** Simple registration pattern allows any plugin or theme to expose their capabilities.
25
25
-**AI-Friendly:** Machine-readable format enables intelligent automation and AI agent interactions.
26
26
27
-
**Use Cases**
27
+
## Use Cases
28
28
29
29
-**AI Integration:** Allow AI agents to discover and interact with site capabilities.
30
30
-**Plugin Interoperability:** Enable plugins to discover and use each other's functionality.
31
31
-**Automation Tools:** Provide programmatic access to site features.
32
32
-**API Documentation:** Self-documenting capabilities with schema validation.
33
33
-**Developer Tools:** Standardized way to expose plugin functionality.
The primary way to add functionality to the Abilities API is by using the `wp_register_ability()` function, typically hooked into the `abilities_api_init` action.
-`$args` (`array`): An array of arguments defining the ability configuration.
13
13
-**Return:** (`?\WP_Ability`) An instance of the registered ability if it was successfully registered, `null` on failure (e.g., invalid arguments, duplicate ID).
14
14
15
-
**Parameters Explained**
15
+
## Parameters Explained
16
16
17
17
The `$args` array accepts the following keys:
18
18
@@ -29,17 +29,17 @@ The `$args` array accepts the following keys:
29
29
- If the input does not validate against the input schema, the permission callback will not be called, and a `WP_Error` will be returned instead.
30
30
-`meta` (`array`, **Optional**): An associative array for storing arbitrary additional metadata about the ability.
31
31
32
-
**Ability ID Convention**
32
+
## Ability ID Convention
33
33
34
34
The `$id` parameter must follow the pattern `namespace/ability-name`:
35
35
36
36
-**Format:** Must contain only lowercase alphanumeric characters (`a-z`, `0-9`), hyphens (`-`), and one forward slash (`/`) for namespacing.
37
37
-**Convention:** Use your plugin slug as the namespace, like `my-plugin/ability-name`.
Before executing an ability, you can check if the current user has permission:
129
+
You can check if the current user has permissions to execute the ability, also without executing it. The `check_permissions()` method returns either `true`, `false`, or a `WP_Error` object. `true` means permission is granted, `false` means the user simply lacks permission, and a `WP_Error` return value typically indicates a failure in the permission check process (such as an internal error or misconfiguration). You must use `is_wp_error()` to handle errors properly and distinguish between permission denial and actual errors:
0 commit comments