Skip to content

Commit 324d332

Browse files
committed
Fix linting issues
1 parent 94fc97d commit 324d332

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

includes/abilities-api.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* alphanumeric characters, dashes and the forward slash.
2626
* @param array<string,mixed> $args An associative array of arguments for the ability. This should include
2727
* `label`, `description`, `input_schema`, `output_schema`, `execute_callback`,
28-
* `permission_callback`, `meta`, and `ability_class`.
28+
* `permission_callback`, `annotations`, `meta`, and `ability_class`.
2929
* @return ?\WP_Ability An instance of registered ability on success, null on failure.
3030
*
3131
* @phpstan-param array{
@@ -35,6 +35,7 @@
3535
* permission_callback?: callable( mixed $input= ): (bool|\WP_Error),
3636
* input_schema?: array<string,mixed>,
3737
* output_schema?: array<string,mixed>,
38+
* annotations?: array<string,mixed>,
3839
* meta?: array<string,mixed>,
3940
* ability_class?: class-string<\WP_Ability>,
4041
* ...<string, mixed>

includes/abilities-api/class-wp-abilities-registry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ final class WP_Abilities_Registry {
5757
* permission_callback?: callable( mixed $input= ): (bool|\WP_Error),
5858
* input_schema?: array<string,mixed>,
5959
* output_schema?: array<string,mixed>,
60+
* annotations?: array<string,mixed>,
6061
* meta?: array<string,mixed>,
6162
* ability_class?: class-string<\WP_Ability>,
6263
* ...<string, mixed>

includes/abilities-api/class-wp-ability.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class WP_Ability {
2626
* @since n.e.x.t
2727
* @var array<string,(bool|string)>
2828
*/
29-
const DEFAULT_ANNOTATIONS = array(
29+
protected static $default_annotations = array(
3030
// An instruction on how to use the ability.
3131
'instruction' => '',
3232
// If true, the ability does not modify its environment.
@@ -41,7 +41,6 @@ class WP_Ability {
4141
* on its environment.
4242
*/
4343
'idempotent' => false,
44-
4544
);
4645

4746
/**
@@ -107,7 +106,7 @@ class WP_Ability {
107106
* @since n.e.x.t
108107
* @var array<string,(bool|string)>
109108
*/
110-
protected $annotations = self::DEFAULT_ANNOTATIONS;
109+
protected $annotations = array();
111110

112111
/**
113112
* The optional ability metadata.
@@ -179,6 +178,7 @@ public function __construct( string $name, array $args ) {
179178
* permission_callback: callable( mixed $input= ): (bool|\WP_Error),
180179
* input_schema?: array<string,mixed>,
181180
* output_schema?: array<string,mixed>,
181+
* annotations?: array<string,mixed>,
182182
* meta?: array<string,mixed>,
183183
* ...<string, mixed>,
184184
* } $args
@@ -222,7 +222,7 @@ protected function prepare_properties( array $args ): array {
222222
);
223223
}
224224

225-
if ( isset( $args['annotations']) && ! is_array( $args['annotations'] ) ) {
225+
if ( isset( $args['annotations'] ) && ! is_array( $args['annotations'] ) ) {
226226
throw new \InvalidArgumentException(
227227
esc_html__( 'The ability properties should provide a valid `annotations` array.' )
228228
);
@@ -234,6 +234,11 @@ protected function prepare_properties( array $args ): array {
234234
);
235235
}
236236

237+
// Set defaults for optional args.
238+
if ( ! isset( $args['annotations'] ) ) {
239+
$args['annotations'] = static::$default_annotations;
240+
}
241+
237242
return $args;
238243
}
239244

0 commit comments

Comments
 (0)