Skip to content

Commit f514ac1

Browse files
gziolojustlevinejonathanbossenger
authored
Sync changes applied to WordPress 6.9 beta 3 (#137)
Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: justlevine <justlevine@git.wordpress.org> Co-authored-by: jonathanbossenger <psykro@git.wordpress.org>
1 parent e309018 commit f514ac1

13 files changed

+387
-287
lines changed

includes/abilities-api.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,16 @@
254254
* @type array<string, mixed> $meta {
255255
* Optional. Additional metadata for the ability.
256256
*
257-
* @type array<string, bool|null> $annotations Optional. Annotation metadata for the ability. Provides
258-
* additional semantic information about the ability's
259-
* characteristics and behavior.
257+
* @type array<string, bool|null> $annotations {
258+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
259+
* These annotations are hints for tooling and documentation.
260+
*
261+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
262+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
263+
* If false, the ability performs only additive updates.
264+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
265+
* will have no additional effect on its environment.
266+
* }
260267
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API.
261268
* When true, the ability can be invoked via HTTP requests.
262269
* Default false.
@@ -269,7 +276,7 @@
269276
* @return WP_Ability|null The registered ability instance on success, `null` on failure.
270277
*/
271278
function wp_register_ability( string $name, array $args ): ?WP_Ability {
272-
if ( ! did_action( 'wp_abilities_api_init' ) ) {
279+
if ( ! doing_action( 'wp_abilities_api_init' ) ) {
273280
_doing_it_wrong(
274281
__FUNCTION__,
275282
sprintf(
@@ -458,7 +465,7 @@ function wp_get_abilities(): array {
458465
* @return WP_Ability_Category|null The registered ability category instance on success, `null` on failure.
459466
*/
460467
function wp_register_ability_category( string $slug, array $args ): ?WP_Ability_Category {
461-
if ( ! did_action( 'wp_abilities_api_categories_init' ) ) {
468+
if ( ! doing_action( 'wp_abilities_api_categories_init' ) ) {
462469
_doing_it_wrong(
463470
__FUNCTION__,
464471
sprintf(

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ final class WP_Abilities_Registry {
6161
* @type array<string, mixed> $meta {
6262
* Optional. Additional metadata for the ability.
6363
*
64-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
64+
* @type array<string, bool|null> $annotations {
65+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
66+
* These annotations are hints for tooling and documentation.
67+
*
68+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
69+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
70+
* If false, the ability performs only additive updates.
71+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
72+
* will have no additional effect on its environment.
73+
* }
6574
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
6675
* }
6776
* @type string $ability_class Optional. Custom class to instantiate instead of WP_Ability.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public static function get_instance(): ?self {
206206
__METHOD__,
207207
sprintf(
208208
// translators: %s: init action.
209-
__( 'Ability API should not be initialized before the %s action has fired' ),
209+
__( 'Ability API should not be initialized before the %s action has fired.' ),
210210
'<code>init</code>'
211211
),
212212
'6.9.0'

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

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WP_Ability {
3333
* They are not guaranteed to provide a faithful description of ability behavior.
3434
*
3535
* @since 6.9.0
36-
* @var array<string, (bool|null)>
36+
* @var array<string, bool|null>
3737
*/
3838
protected static $default_annotations = array(
3939
// If true, the ability does not modify its environment.
@@ -150,7 +150,16 @@ class WP_Ability {
150150
* @type array<string, mixed> $meta {
151151
* Optional. Additional metadata for the ability.
152152
*
153-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
153+
* @type array<string, bool|null> $annotations {
154+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
155+
* These annotations are hints for tooling and documentation.
156+
*
157+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
158+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
159+
* If false, the ability performs only additive updates.
160+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
161+
* will have no additional effect on its environment.
162+
* }
154163
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
155164
* }
156165
* }
@@ -205,7 +214,16 @@ public function __construct( string $name, array $args ) {
205214
* @type array<string, mixed> $meta {
206215
* Optional. Additional metadata for the ability.
207216
*
208-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
217+
* @type array<string, bool|null> $annotations {
218+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
219+
* These annotations are hints for tooling and documentation.
220+
*
221+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
222+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
223+
* If false, the ability performs only additive updates.
224+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
225+
* will have no additional effect on its environment.
226+
* }
209227
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
210228
* }
211229
* }
@@ -224,7 +242,16 @@ public function __construct( string $name, array $args ) {
224242
* @type array<string, mixed> $meta {
225243
* Additional metadata for the ability.
226244
*
227-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
245+
* @type array<string, bool|null> $annotations {
246+
* Semantic annotations describing the ability's behavioral characteristics.
247+
* These annotations are hints for tooling and documentation.
248+
*
249+
* @type bool|null $readonly If true, the ability does not modify its environment.
250+
* @type bool|null $destructive If true, the ability may perform destructive updates to its environment.
251+
* If false, the ability performs only additive updates.
252+
* @type bool|null $idempotent If true, calling the ability repeatedly with the same arguments
253+
* will have no additional effect on its environment.
254+
* }
228255
* @type bool $show_in_rest Whether to expose this ability in the REST API. Default false.
229256
* }
230257
* }
@@ -498,6 +525,14 @@ protected function invoke_callback( callable $callback, $input = null ) {
498525
* @return bool|WP_Error Whether the ability has the necessary permission.
499526
*/
500527
public function check_permissions( $input = null ) {
528+
if ( ! is_callable( $this->permission_callback ) ) {
529+
return new WP_Error(
530+
'ability_invalid_permission_callback',
531+
/* translators: %s ability name. */
532+
sprintf( __( 'Ability "%s" does not have a valid permission callback.' ), esc_html( $this->name ) )
533+
);
534+
}
535+
501536
return $this->invoke_callback( $this->permission_callback, $input );
502537
}
503538

tests/unit/abilities-api/wpAbilitiesRegistry.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ public function set_up(): void {
2929

3030
remove_all_filters( 'wp_register_ability_args' );
3131

32-
// Fire the init hook to allow test ability category registration.
33-
do_action( 'wp_abilities_api_categories_init' );
32+
// Simulates the Abilities API init hook to allow test ability category registration.
33+
global $wp_current_filter;
34+
$wp_current_filter[] = 'wp_abilities_api_categories_init';
3435
wp_register_ability_category(
3536
'math',
3637
array(
3738
'label' => 'Math',
3839
'description' => 'Mathematical operations and calculations.',
3940
)
4041
);
42+
array_pop( $wp_current_filter );
4143

4244
self::$test_ability_args = array(
4345
'label' => 'Add numbers',

tests/unit/abilities-api/wpAbility.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ class Tests_Abilities_API_WpAbility extends WP_UnitTestCase {
1818
public function set_up(): void {
1919
parent::set_up();
2020

21-
// Fire the init hook to allow test ability category registration.
22-
do_action( 'wp_abilities_api_categories_init' );
23-
wp_register_ability_category(
24-
'math',
25-
array(
26-
'label' => 'Math',
27-
'description' => 'Mathematical operations and calculations.',
28-
)
29-
);
30-
3121
self::$test_ability_properties = array(
3222
'label' => 'Calculator',
3323
'description' => 'Calculates the result of math operations.',
@@ -56,9 +46,6 @@ public function set_up(): void {
5646
* Tear down after each test.
5747
*/
5848
public function tear_down(): void {
59-
// Clean up registered test ability category.
60-
wp_unregister_ability_category( 'math' );
61-
6249
parent::tear_down();
6350
}
6451

tests/unit/abilities-api/wpCoreAbilities.php

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)