@@ -26,7 +26,7 @@ class WP_Ability {
26
26
* @since n.e.x.t
27
27
* @var array<string,(bool|string)>
28
28
*/
29
- const DEFAULT_ANNOTATIONS = array (
29
+ protected static $ default_annotations = array (
30
30
// An instruction on how to use the ability.
31
31
'instruction ' => '' ,
32
32
// If true, the ability does not modify its environment.
@@ -41,7 +41,6 @@ class WP_Ability {
41
41
* on its environment.
42
42
*/
43
43
'idempotent ' => false ,
44
-
45
44
);
46
45
47
46
/**
@@ -107,7 +106,7 @@ class WP_Ability {
107
106
* @since n.e.x.t
108
107
* @var array<string,(bool|string)>
109
108
*/
110
- protected $ annotations = self :: DEFAULT_ANNOTATIONS ;
109
+ protected $ annotations = array () ;
111
110
112
111
/**
113
112
* The optional ability metadata.
@@ -179,6 +178,7 @@ public function __construct( string $name, array $args ) {
179
178
* permission_callback: callable( mixed $input= ): (bool|\WP_Error),
180
179
* input_schema?: array<string,mixed>,
181
180
* output_schema?: array<string,mixed>,
181
+ * annotations?: array<string,mixed>,
182
182
* meta?: array<string,mixed>,
183
183
* ...<string, mixed>,
184
184
* } $args
@@ -222,7 +222,7 @@ protected function prepare_properties( array $args ): array {
222
222
);
223
223
}
224
224
225
- if ( isset ( $ args ['annotations ' ]) && ! is_array ( $ args ['annotations ' ] ) ) {
225
+ if ( isset ( $ args ['annotations ' ] ) && ! is_array ( $ args ['annotations ' ] ) ) {
226
226
throw new \InvalidArgumentException (
227
227
esc_html__ ( 'The ability properties should provide a valid `annotations` array. ' )
228
228
);
@@ -234,6 +234,11 @@ protected function prepare_properties( array $args ): array {
234
234
);
235
235
}
236
236
237
+ // Set defaults for optional args.
238
+ if ( ! isset ( $ args ['annotations ' ] ) ) {
239
+ $ args ['annotations ' ] = static ::$ default_annotations ;
240
+ }
241
+
237
242
return $ args ;
238
243
}
239
244
0 commit comments