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/3.registering-abilities.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,11 @@ The `$args` array accepts the following keys:
28
28
- The callback should return a boolean (`true` if the user has permission, `false` otherwise), or a `WP_Error` object on failure.
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
+
-`annotations` (`array`, **Optional**): An associative array of annotations providing hints about the ability's behavior characteristics. Supports the following keys:
32
+
-`instructions` (`string`, **Optional**): Custom instructions or guidance for using the ability (default: `''`).
33
+
-`readonly` (`boolean`, **Optional**): Whether the ability only reads data without modifying its environment (default: `false`).
34
+
-`destructive` (`boolean`, **Optional**): Whether the ability may perform destructive updates to its environment. If `true`, the ability may perform any type of modification, including deletions or other destructive changes. If `false`, the ability performs only additive updates (default: `true`).
35
+
-`idempotent` (`boolean`, **Optional**): Whether calling the ability repeatedly with the same arguments will have no additional effect on its environment (default: `false`).
31
36
-`show_in_rest` (`boolean`, **Optional**): Whether to expose this ability via the REST API. Default: `false`.
32
37
- When `true`, the ability will be listed in REST API responses and can be executed via REST endpoints.
33
38
- When `false`, the ability will be hidden from REST API listings and cannot be executed via REST endpoints, but remains available for internal PHP usage.
@@ -80,7 +85,13 @@ function my_plugin_register_site_info_ability() {
80
85
'url' => home_url()
81
86
);
82
87
},
83
-
'permission_callback' => '__return_true'
88
+
'permission_callback' => '__return_true',
89
+
'meta' => array(
90
+
'annotations' => array(
91
+
'readonly' => true,
92
+
'destructive' => false
93
+
),
94
+
),
84
95
));
85
96
}
86
97
```
@@ -134,7 +145,13 @@ function my_plugin_register_update_option_ability() {
curl -X POST https://example.com/wp-json/wp/v2/abilities/my-plugin/create-draft/run
192
+
193
+
# With input
156
194
curl -X POST \
157
195
-H "Content-Type: application/json" \
158
196
-d '{"input":{"option_name":"blogname","option_value":"New Site Name"}}' \
@@ -205,5 +243,5 @@ The API returns standard WordPress REST API error responses with these common co
205
243
-`ability_invalid_output` - output validation failed according to the ability's schema.
206
244
-`ability_invalid_execute_callback` - the ability's execute callback is not callable.
207
245
-`rest_ability_not_found` - the requested ability is not registered.
208
-
-`rest_ability_invalid_method` - the requested HTTP method is not allowed for executing the selected ability.
246
+
-`rest_ability_invalid_method` - the requested HTTP method is not allowed for executing the selected ability (e.g., using GET on a read-only ability, or POST on a regular ability).
209
247
-`rest_ability_cannot_execute` - the ability cannot be executed due to insufficient permissions.
0 commit comments