Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Commit d52ad8c

Browse files
Jameswlepageclaude
andcommitted
Fix linting issues and update hook naming
- Update filter hook name to wp_find_abilities_results for core consistency - Remove text domains from translation functions (core uses default domain) - Fix execute callback signatures to use optional parameters - Inline test environment check in bootstrap.php 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ca8e54a commit d52ad8c

File tree

2 files changed

+56
-54
lines changed

2 files changed

+56
-54
lines changed

includes/abilities/class-wp-core-abilities.php

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* @since n.e.x.t
1616
*/
17+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Core class intended for WordPress core.
1718
class WP_Core_Abilities {
1819
/**
1920
* Registers the default core abilities.
@@ -51,15 +52,15 @@ protected static function register_get_bloginfo(): void {
5152
wp_register_ability(
5253
'core/get-bloginfo',
5354
array(
54-
'label' => __( 'Get Blog Information', 'abilities-api' ),
55-
'description' => __( 'Returns a single site information field from get_bloginfo().', 'abilities-api' ),
55+
'label' => __( 'Get Blog Information' ),
56+
'description' => __( 'Returns a single site information field from get_bloginfo().' ),
5657
'input_schema' => array(
5758
'type' => 'object',
5859
'properties' => array(
5960
'field' => array(
6061
'type' => 'string',
6162
'enum' => $fields,
62-
'description' => __( 'The site information field to retrieve.', 'abilities-api' ),
63+
'description' => __( 'The site information field to retrieve.' ),
6364
),
6465
),
6566
'required' => array( 'field' ),
@@ -71,16 +72,16 @@ protected static function register_get_bloginfo(): void {
7172
'properties' => array(
7273
'field' => array(
7374
'type' => 'string',
74-
'description' => __( 'The requested site information field.', 'abilities-api' ),
75+
'description' => __( 'The requested site information field.' ),
7576
),
7677
'value' => array(
7778
'type' => 'string',
78-
'description' => __( 'The value returned by get_bloginfo().', 'abilities-api' ),
79+
'description' => __( 'The value returned by get_bloginfo().' ),
7980
),
8081
),
8182
'additionalProperties' => false,
8283
),
83-
'execute_callback' => static function ( array $input ): array {
84+
'execute_callback' => static function ( $input = array() ): array {
8485
$field = $input['field'];
8586
$value = get_bloginfo( $field );
8687

@@ -92,7 +93,7 @@ protected static function register_get_bloginfo(): void {
9293
'permission_callback' => '__return_true',
9394
'meta' => array(
9495
'annotations' => array(
95-
'instructions' => __( 'Retrieves a single site property by passing an allowed field to get_bloginfo().', 'abilities-api' ),
96+
'instructions' => __( 'Retrieves a single site property by passing an allowed field to get_bloginfo().' ),
9697
'readonly' => true,
9798
'destructive' => false,
9899
'idempotent' => true,
@@ -114,38 +115,38 @@ protected static function register_get_current_user_info(): void {
114115
wp_register_ability(
115116
'core/get-current-user-info',
116117
array(
117-
'label' => __( 'Get Current User Information', 'abilities-api' ),
118-
'description' => __( 'Returns basic information about the current authenticated user.', 'abilities-api' ),
118+
'label' => __( 'Get Current User Information' ),
119+
'description' => __( 'Returns basic information about the current authenticated user.' ),
119120
'output_schema' => array(
120121
'type' => 'object',
121122
'required' => array( 'id', 'display_name', 'locale' ),
122123
'properties' => array(
123-
'id' => array(
124+
'id' => array(
124125
'type' => 'integer',
125-
'description' => __( 'The user ID.', 'abilities-api' ),
126+
'description' => __( 'The user ID.' ),
126127
),
127-
'display_name' => array(
128+
'display_name' => array(
128129
'type' => 'string',
129-
'description' => __( 'The display name of the user.', 'abilities-api' ),
130+
'description' => __( 'The display name of the user.' ),
130131
),
131132
'user_nicename' => array(
132133
'type' => 'string',
133-
'description' => __( 'The URL-friendly name for the user.', 'abilities-api' ),
134+
'description' => __( 'The URL-friendly name for the user.' ),
134135
),
135-
'user_login' => array(
136+
'user_login' => array(
136137
'type' => 'string',
137-
'description' => __( 'The login username for the user.', 'abilities-api' ),
138+
'description' => __( 'The login username for the user.' ),
138139
),
139-
'roles' => array(
140+
'roles' => array(
140141
'type' => 'array',
141-
'description' => __( 'The roles assigned to the user.', 'abilities-api' ),
142+
'description' => __( 'The roles assigned to the user.' ),
142143
'items' => array(
143144
'type' => 'string',
144145
),
145146
),
146-
'locale' => array(
147+
'locale' => array(
147148
'type' => 'string',
148-
'description' => __( 'The locale string for the user, such as en_US.', 'abilities-api' ),
149+
'description' => __( 'The locale string for the user, such as en_US.' ),
149150
),
150151
),
151152
'additionalProperties' => false,
@@ -154,20 +155,20 @@ protected static function register_get_current_user_info(): void {
154155
$current_user = wp_get_current_user();
155156

156157
return array(
157-
'id' => $current_user->ID,
158-
'display_name' => $current_user->display_name,
158+
'id' => $current_user->ID,
159+
'display_name' => $current_user->display_name,
159160
'user_nicename' => $current_user->user_nicename,
160-
'user_login' => $current_user->user_login,
161-
'roles' => $current_user->roles,
162-
'locale' => get_user_locale( $current_user ),
161+
'user_login' => $current_user->user_login,
162+
'roles' => $current_user->roles,
163+
'locale' => get_user_locale( $current_user ),
163164
);
164165
},
165166
'permission_callback' => static function (): bool {
166167
return is_user_logged_in();
167168
},
168169
'meta' => array(
169170
'annotations' => array(
170-
'instructions' => __( 'Retrieves information about the current authenticated user.', 'abilities-api' ),
171+
'instructions' => __( 'Retrieves information about the current authenticated user.' ),
171172
'readonly' => true,
172173
'destructive' => false,
173174
'idempotent' => true,
@@ -189,15 +190,15 @@ protected static function register_get_environment_type(): void {
189190
wp_register_ability(
190191
'core/get-environment-type',
191192
array(
192-
'label' => __( 'Get Environment Type', 'abilities-api' ),
193-
'description' => __( 'Returns the current WordPress environment type (e.g. production or staging).', 'abilities-api' ),
193+
'label' => __( 'Get Environment Type' ),
194+
'description' => __( 'Returns the current WordPress environment type (e.g. production or staging).' ),
194195
'output_schema' => array(
195196
'type' => 'object',
196197
'required' => array( 'environment' ),
197198
'properties' => array(
198199
'environment' => array(
199200
'type' => 'string',
200-
'description' => __( 'The environment type returned by wp_get_environment_type().', 'abilities-api' ),
201+
'description' => __( 'The environment type returned by wp_get_environment_type().' ),
201202
),
202203
),
203204
'additionalProperties' => false,
@@ -210,7 +211,7 @@ protected static function register_get_environment_type(): void {
210211
'permission_callback' => '__return_true',
211212
'meta' => array(
212213
'annotations' => array(
213-
'instructions' => __( 'Retrieves the current WordPress environment type.', 'abilities-api' ),
214+
'instructions' => __( 'Retrieves the current WordPress environment type.' ),
214215
'readonly' => true,
215216
'destructive' => false,
216217
'idempotent' => true,
@@ -232,53 +233,53 @@ protected static function register_find_abilities(): void {
232233
wp_register_ability(
233234
'core/find-abilities',
234235
array(
235-
'label' => __( 'Find Abilities', 'abilities-api' ),
236-
'description' => __( 'Returns a list of abilities that are exposed through the registry.', 'abilities-api' ),
236+
'label' => __( 'Find Abilities' ),
237+
'description' => __( 'Returns a list of abilities that are exposed through the registry.' ),
237238
'input_schema' => array(
238239
'type' => array( 'object', 'null' ),
239240
'properties' => array(
240-
'namespace' => array(
241+
'namespace' => array(
241242
'type' => 'string',
242-
'description' => __( 'Optional namespace prefix to filter abilities (e.g. "core/").', 'abilities-api' ),
243+
'description' => __( 'Optional namespace prefix to filter abilities (e.g. "core/").' ),
243244
),
244245
'show_in_rest' => array(
245246
'type' => 'boolean',
246-
'description' => __( 'Whether to limit results to abilities exposed in REST. Defaults to true.', 'abilities-api' ),
247+
'description' => __( 'Whether to limit results to abilities exposed in REST. Defaults to true.' ),
247248
),
248249
),
249250
'additionalProperties' => false,
250251
),
251252
'output_schema' => array(
252-
'type' => 'object',
253-
'properties' => array(
253+
'type' => 'object',
254+
'properties' => array(
254255
'abilities' => array(
255256
'type' => 'array',
256257
'items' => array(
257258
'type' => 'object',
258259
'properties' => array(
259-
'name' => array(
260+
'name' => array(
260261
'type' => 'string',
261-
'description' => __( 'The ability name.', 'abilities-api' ),
262+
'description' => __( 'The ability name.' ),
262263
),
263-
'label' => array(
264+
'label' => array(
264265
'type' => 'string',
265-
'description' => __( 'The human readable label.', 'abilities-api' ),
266+
'description' => __( 'The human readable label.' ),
266267
),
267-
'description' => array(
268+
'description' => array(
268269
'type' => 'string',
269-
'description' => __( 'The detailed description.', 'abilities-api' ),
270+
'description' => __( 'The detailed description.' ),
270271
),
271-
'meta' => array(
272+
'meta' => array(
272273
'type' => 'object',
273-
'description' => __( 'Additional metadata associated with the ability.', 'abilities-api' ),
274+
'description' => __( 'Additional metadata associated with the ability.' ),
274275
),
275-
'annotations' => array(
276+
'annotations' => array(
276277
'type' => 'object',
277-
'description' => __( 'Annotations describing ability behavior.', 'abilities-api' ),
278+
'description' => __( 'Annotations describing ability behavior.' ),
278279
),
279280
'show_in_rest' => array(
280281
'type' => 'boolean',
281-
'description' => __( 'Whether the ability is exposed in REST.', 'abilities-api' ),
282+
'description' => __( 'Whether the ability is exposed in REST.' ),
282283
),
283284
),
284285
'required' => array( 'name', 'label', 'description', 'meta', 'annotations', 'show_in_rest' ),
@@ -287,7 +288,7 @@ protected static function register_find_abilities(): void {
287288
),
288289
'additionalProperties' => false,
289290
),
290-
'execute_callback' => static function ( array $input = array() ): array {
291+
'execute_callback' => static function ( $input = array() ): array {
291292
$namespace = $input['namespace'] ?? null;
292293
$filter_rest = array_key_exists( 'show_in_rest', $input ) ? (bool) $input['show_in_rest'] : true;
293294
$abilities = wp_get_abilities();
@@ -299,7 +300,7 @@ protected static function register_find_abilities(): void {
299300
continue;
300301
}
301302

302-
if ( $namespace && ! str_starts_with( $ability->get_name(), $namespace ) ) {
303+
if ( $namespace && 0 !== strpos( $ability->get_name(), $namespace ) ) {
303304
continue;
304305
}
305306

@@ -321,7 +322,8 @@ protected static function register_find_abilities(): void {
321322
* @param array<string,mixed>[] $abilities An array of abilities exposed by the ability.
322323
* @param array<string,mixed> $input The input arguments passed to the ability.
323324
*/
324-
$filtered_list = apply_filters( 'abilities_api_core_find_abilities_results', $filtered_list, $input );
325+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core hook intended for WordPress core.
326+
$filtered_list = apply_filters( 'wp_find_abilities_results', $filtered_list, $input );
325327

326328
return array(
327329
'abilities' => array_values( $filtered_list ),
@@ -332,7 +334,7 @@ protected static function register_find_abilities(): void {
332334
},
333335
'meta' => array(
334336
'annotations' => array(
335-
'instructions' => __( 'Lists abilities from the registry. Optional namespace filter is supported.', 'abilities-api' ),
337+
'instructions' => __( 'Lists abilities from the registry. Optional namespace filter is supported.' ),
336338
'readonly' => true,
337339
'destructive' => false,
338340
'idempotent' => true,

includes/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
}
4242

4343
// Register core abilities when requested via filter or when not in test environment.
44-
$is_test_env = defined( 'WP_RUN_CORE_TESTS' ) || defined( 'WP_TESTS_CONFIG_FILE_PATH' ) || ( function_exists( 'getenv' ) && false !== getenv( 'WP_PHPUNIT__DIR' ) );
45-
if ( ! $is_test_env || apply_filters( 'abilities_api_register_core_abilities', false ) ) {
44+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Plugin-specific hook for feature plugin context.
45+
if ( ! ( defined( 'WP_RUN_CORE_TESTS' ) || defined( 'WP_TESTS_CONFIG_FILE_PATH' ) || ( function_exists( 'getenv' ) && false !== getenv( 'WP_PHPUNIT__DIR' ) ) ) || apply_filters( 'abilities_api_register_core_abilities', false ) ) {
4646
if ( function_exists( 'add_action' ) ) {
4747
add_action( 'abilities_api_init', array( 'WP_Core_Abilities', 'register' ) );
4848
}

0 commit comments

Comments
 (0)