Skip to content

Commit cc03046

Browse files
huzaifaalmesbahgziolomindctrl
authored
fix(docs): correct invalid function references and parameter placement (#140)
- Replace non-existent wp_execute_ability() with correct wp_get_ability() and ->execute() pattern - Move 'category' parameter from meta array to top-level args array in examples - Fix class name from WP_Abilities_Category_Registry to WP_Ability_Categories_Registry The documentation incorrectly referenced wp_execute_ability() which does not exist in the codebase (verified in includes/abilities-api.php lines 278-607). The correct approach is to use wp_get_ability() to retrieve the ability object, then call its execute() method (defined in includes/abilities-api/class-wp-ability.php line 595). Additionally, code examples showed 'category' inside the meta array, but per the function signature (includes/abilities-api.php line 237) and core implementation (includes/abilities/wp-core-abilities.php line 89), category must be a top-level parameter. Fixes documentation accuracy to match actual codebase implementation. Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl> Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: mindctrl <mindctrl@git.wordpress.org>
1 parent 0a1cda6 commit cc03046

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

docs/getting-started.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function my_plugin_register_abilities() {
110110
wp_register_ability( 'my-plugin/get-site-title', array(
111111
'label' => __( 'Get Site Title', 'my-plugin' ),
112112
'description' => __( 'Retrieves the title of the current WordPress site.', 'my-plugin' ),
113+
'category' => 'site-info',
113114
'input_schema' => array(
114115
'type' => 'object',
115116
'properties' => array(),
@@ -122,8 +123,8 @@ function my_plugin_register_abilities() {
122123
'execute_callback' => 'my_plugin_get_site_title',
123124
'permission_callback' => '__return_true', // Everyone can access this
124125
'meta' => array(
125-
'category' => 'site-info',
126126
'show_in_rest' => true, // Optional: expose via REST API
127+
),
127128
) );
128129
}
129130

docs/hooks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ do_action( 'wp_abilities_api_categories_init', $registry );
2525

2626
#### Parameters
2727

28-
- `$registry` (`\WP_Abilities_Category_Registry`): The category registry instance.
28+
- `$registry` (`\WP_Ability_Categories_Registry`): The category registry instance.
2929

3030
#### Usage Example
3131

@@ -34,7 +34,7 @@ add_action( 'wp_abilities_api_categories_init', 'my_plugin_register_categories'
3434
/**
3535
* Register custom ability categories.
3636
*
37-
* @param \WP_Abilities_Category_Registry $registry The category registry instance.
37+
* @param \WP_Ability_Categories_Registry $registry The category registry instance.
3838
*/
3939
function my_plugin_register_categories( $registry ) {
4040
wp_register_ability_category( 'ecommerce', array(
@@ -85,8 +85,8 @@ function my_plugin_register_abilities() {
8585
'execute_callback' => 'my_plugin_get_site_title',
8686
'permission_callback' => '__return_true', // Everyone can access this
8787
'meta' => array(
88-
'category' => 'site-info',
8988
'show_in_rest' => true, // Optional: expose via REST API
89+
),
9090
) );
9191
}
9292
```

docs/rest-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Access to all Abilities REST API endpoints requires an authenticated user (see t
1111
By default, registered abilities are **not** exposed via the REST API. You can control whether an individual ability appears in the REST API by using the `show_in_rest` meta when registering the ability:
1212

1313
- `show_in_rest => true`: The ability is listed in REST API responses and can be executed via REST endpoints.
14-
- `show_in_rest => false` (default): The ability is hidden from REST API listings and cannot be executed via REST endpoints. The ability remains available for internal PHP usage via `wp_execute_ability()`.
14+
- `show_in_rest => false` (default): The ability is hidden from REST API listings and cannot be executed via REST endpoints. The ability remains available for internal PHP usage via `wp_get_ability()` and `$ability->execute()`.
1515

1616
Abilities with meta `show_in_rest => false` will return a `rest_ability_not_found` error if accessed via REST endpoints.
1717

0 commit comments

Comments
 (0)