From a57a432e11d22c403158121ef84f91c477969561 Mon Sep 17 00:00:00 2001 From: Avinash Date: Tue, 24 Nov 2026 18:27:35 +0530 Subject: [PATCH 1/3] Abilities API: Add an open world annotation. Adds `open_world` as an optional `bool|null` ability annotation, defaulting to `null`, and documents it in the REST schema and the registration docblocks. Props avinashzala01. See #66799. --- src/wp-includes/abilities-api.php | 2 + .../class-wp-abilities-registry.php | 2 + .../abilities-api/class-wp-ability.php | 11 ++++++ ...s-wp-rest-abilities-v1-list-controller.php | 8 ++++ .../phpunit/tests/abilities-api/wpAbility.php | 37 +++++++++++++++++++ .../tests/abilities-api/wpRegisterAbility.php | 1 + 6 files changed, 61 insertions(+) diff --git a/src/wp-includes/abilities-api.php b/src/wp-includes/abilities-api.php index 50f4b6ac05610..821f2fae0e1cc 100644 --- a/src/wp-includes/abilities-api.php +++ b/src/wp-includes/abilities-api.php @@ -341,6 +341,8 @@ * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. + * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. + * If false, the ability stays within a bounded environment. If null, it is not declared. * } * @type bool $public Optional. Whether the ability is meant to be available to * clients such as the REST API, MCP, or AI agents. Seeds diff --git a/src/wp-includes/abilities-api/class-wp-abilities-registry.php b/src/wp-includes/abilities-api/class-wp-abilities-registry.php index dc0b30835d9d1..9ac16bc31e968 100644 --- a/src/wp-includes/abilities-api/class-wp-abilities-registry.php +++ b/src/wp-includes/abilities-api/class-wp-abilities-registry.php @@ -76,6 +76,8 @@ final class WP_Abilities_Registry { * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. + * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. + * If false, the ability stays within a bounded environment. If null, it is not declared. * } * @type bool $public Optional. Whether the ability is meant to be available * to clients such as the REST API, MCP, or AI agents. diff --git a/src/wp-includes/abilities-api/class-wp-ability.php b/src/wp-includes/abilities-api/class-wp-ability.php index 3e9dc2c18fdac..898472f9cfe49 100644 --- a/src/wp-includes/abilities-api/class-wp-ability.php +++ b/src/wp-includes/abilities-api/class-wp-ability.php @@ -56,6 +56,11 @@ class WP_Ability { * on its environment. */ 'idempotent' => null, + /* + * If true, at least one supported execution path may interact with public or open-ended entities. + * If false, all supported execution paths stay within a bounded environment. + */ + 'open_world' => null, ); /** @@ -181,6 +186,8 @@ class WP_Ability { * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. + * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. + * If false, the ability stays within a bounded environment. If null, it is not declared. * } * @type bool $public Optional. Whether the ability is meant to be available * to clients such as the REST API, MCP, or AI agents. @@ -256,6 +263,8 @@ public function __construct( string $name, array $args ) { * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. + * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. + * If false, the ability stays within a bounded environment. If null, it is not declared. * } * @type bool $public Optional. Whether the ability is meant to be available * to clients such as the REST API, MCP, or AI agents. @@ -293,6 +302,8 @@ public function __construct( string $name, array $args ) { * If false, the ability performs only additive updates. * @type bool|null $idempotent If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. + * @type bool|null $open_world If true, the ability may interact with public or open-ended entities. + * If false, the ability stays within a bounded environment. If null, it is not declared. * } * @type bool $public Whether the ability is meant to be available to clients * such as the REST API, MCP, or AI agents. Defaults to diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php index da2bb71fc51fd..222a3220d912d 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php @@ -325,6 +325,10 @@ public function get_item_schema(): array { 'description' => __( 'Whether repeated calls with the same arguments have no additional effect.' ), 'type' => array( 'boolean', 'null' ), ), + 'open_world' => array( + 'description' => __( 'Whether the ability may interact with public or open-ended entities.' ), + 'type' => array( 'boolean', 'null' ), + ), ), 'additionalProperties' => true, ), @@ -400,6 +404,10 @@ public function get_collection_params(): array { 'description' => __( 'Whether repeated calls with the same arguments have no additional effect.' ), 'type' => array( 'boolean', 'null' ), ), + 'open_world' => array( + 'description' => __( 'Whether the ability may interact with public or open-ended entities.' ), + 'type' => array( 'boolean', 'null' ), + ), ), 'additionalProperties' => true, ), diff --git a/tests/phpunit/tests/abilities-api/wpAbility.php b/tests/phpunit/tests/abilities-api/wpAbility.php index d779de4cc37b7..ac95e0dd40c36 100644 --- a/tests/phpunit/tests/abilities-api/wpAbility.php +++ b/tests/phpunit/tests/abilities-api/wpAbility.php @@ -110,6 +110,7 @@ public function test_get_merged_annotations_from_meta() { self::$test_ability_properties['meta']['annotations'], array( 'idempotent' => null, + 'open_world' => null, ) ), $ability->get_meta_item( 'annotations' ) @@ -132,6 +133,7 @@ public function test_get_default_annotations_from_meta() { 'readonly' => null, 'destructive' => null, 'idempotent' => null, + 'open_world' => null, ), $ability->get_meta_item( 'annotations' ) ); @@ -147,6 +149,7 @@ public function test_get_overridden_annotations_from_meta() { 'readonly' => true, 'destructive' => false, 'idempotent' => false, + 'open_world' => true, ); $args = array_merge( self::$test_ability_properties, @@ -162,6 +165,40 @@ public function test_get_overridden_annotations_from_meta() { $this->assertSame( $annotations, $ability->get_meta_item( 'annotations' ) ); } + /** + * Tests that the `open_world` annotation preserves explicit values and stays unspecified otherwise. + * + * @ticket 66799 + * + * @dataProvider data_open_world_annotation + * + * @param array $annotations Annotations passed at registration. + * @param bool|null $expected Expected `open_world` value. + */ + public function test_open_world_annotation( array $annotations, $expected ) { + $args = self::$test_ability_properties; + $args['meta'] = array( 'annotations' => $annotations ); + $ability = new WP_Ability( self::$test_ability_name, $args ); + $resolved_annotations = $ability->get_meta_item( 'annotations' ); + + $this->assertArrayHasKey( 'open_world', $resolved_annotations, 'The annotation should always be present.' ); + $this->assertSame( $expected, $resolved_annotations['open_world'] ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_open_world_annotation(): array { + return array( + 'explicit true' => array( array( 'open_world' => true ), true ), + 'explicit false' => array( array( 'open_world' => false ), false ), + 'explicit null' => array( array( 'open_world' => null ), null ), + 'omitted' => array( array( 'readonly' => true ), null ), + ); + } + /** * Tests that invalid `annotations` value throws an exception. * diff --git a/tests/phpunit/tests/abilities-api/wpRegisterAbility.php b/tests/phpunit/tests/abilities-api/wpRegisterAbility.php index 9a248b76ae478..ba2557cc62edb 100644 --- a/tests/phpunit/tests/abilities-api/wpRegisterAbility.php +++ b/tests/phpunit/tests/abilities-api/wpRegisterAbility.php @@ -185,6 +185,7 @@ public function test_register_valid_ability(): void { self::$test_ability_args['meta']['annotations'], array( 'idempotent' => null, + 'open_world' => null, ) ); $expected_meta = array_merge( From 552db194c9039c3cb685624fd5e7357a107d15b8 Mon Sep 17 00:00:00 2001 From: Avinash Date: Wed, 25 Nov 2026 11:15:32 +0530 Subject: [PATCH 2/3] Tests: Update the generated REST API fixture for the open_world annotation. See #66799. --- tests/qunit/fixtures/wp-api-generated.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index ba63e6425b7fd..d361a954367c4 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -12787,6 +12787,13 @@ mockedApiResponse.Schema = { "boolean", "null" ] + }, + "open_world": { + "description": "Whether the ability may interact with public or open-ended entities.", + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": true From abc4456bd68496c51c47056d8abe72a23f7988e0 Mon Sep 17 00:00:00 2001 From: Avinash Date: Wed, 25 Nov 2026 15:18:04 +0530 Subject: [PATCH 3/3] Abilities API: Clarify the open_world description and add @since notes. Describes the annotation in terms of systems outside of the site, so it is not confused with the `public` meta key, and uses the same wording everywhere. Adds `@since 7.3.0` entries and a REST test that the `open_world` filter value is coerced from a string. See #66799. --- src/wp-includes/abilities-api.php | 6 +- .../class-wp-abilities-registry.php | 7 ++- .../abilities-api/class-wp-ability.php | 22 ++++--- ...s-wp-rest-abilities-v1-list-controller.php | 6 +- .../wpRestAbilitiesV1ListController.php | 57 +++++++++++++++++++ tests/qunit/fixtures/wp-api-generated.js | 2 +- 6 files changed, 85 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/abilities-api.php b/src/wp-includes/abilities-api.php index 821f2fae0e1cc..da44cea0469f9 100644 --- a/src/wp-includes/abilities-api.php +++ b/src/wp-includes/abilities-api.php @@ -286,6 +286,7 @@ * @since 6.9.0 * @since 7.1.0 Added the `public` meta argument. * @since 7.2.0 Added the `required_capabilities` argument. + * @since 7.3.0 Added the `open_world` annotation. * * @see WP_Abilities_Registry::register() * @see WP_Ability::execute() @@ -341,8 +342,9 @@ * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. - * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. - * If false, the ability stays within a bounded environment. If null, it is not declared. + * @type bool|null $open_world Optional. If true, the ability may interact with systems outside of the site, + * such as remote HTTP services or email recipients. If false, the ability + * only interacts with the site itself. * } * @type bool $public Optional. Whether the ability is meant to be available to * clients such as the REST API, MCP, or AI agents. Seeds diff --git a/src/wp-includes/abilities-api/class-wp-abilities-registry.php b/src/wp-includes/abilities-api/class-wp-abilities-registry.php index 9ac16bc31e968..72512d14777f1 100644 --- a/src/wp-includes/abilities-api/class-wp-abilities-registry.php +++ b/src/wp-includes/abilities-api/class-wp-abilities-registry.php @@ -42,6 +42,7 @@ final class WP_Abilities_Registry { * @since 6.9.0 * @since 7.1.0 Added the `public` meta argument. * @since 7.2.0 Added the `required_capabilities` argument. + * @since 7.3.0 Added the `open_world` annotation. * * @see wp_register_ability() * @@ -76,8 +77,9 @@ final class WP_Abilities_Registry { * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. - * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. - * If false, the ability stays within a bounded environment. If null, it is not declared. + * @type bool|null $open_world Optional. If true, the ability may interact with systems outside of the site, + * such as remote HTTP services or email recipients. If false, the ability + * only interacts with the site itself. * } * @type bool $public Optional. Whether the ability is meant to be available * to clients such as the REST API, MCP, or AI agents. @@ -120,6 +122,7 @@ public function register( string $name, array $args ): ?WP_Ability { * @since 6.9.0 * @since 7.1.0 Added the `public` meta argument. * @since 7.2.0 Added the `required_capabilities` argument. + * @since 7.3.0 Added the `open_world` annotation. * * @param array $args { * An associative array of arguments for the ability. diff --git a/src/wp-includes/abilities-api/class-wp-ability.php b/src/wp-includes/abilities-api/class-wp-ability.php index 898472f9cfe49..4a2aa2f354f2a 100644 --- a/src/wp-includes/abilities-api/class-wp-ability.php +++ b/src/wp-includes/abilities-api/class-wp-ability.php @@ -57,8 +57,9 @@ class WP_Ability { */ 'idempotent' => null, /* - * If true, at least one supported execution path may interact with public or open-ended entities. - * If false, all supported execution paths stay within a bounded environment. + * If true, at least one supported execution path may interact with systems outside of the site, + * such as remote HTTP services or email recipients. + * If false, all supported execution paths only interact with the site itself. */ 'open_world' => null, ); @@ -154,6 +155,7 @@ class WP_Ability { * @since 6.9.0 * @since 7.1.0 Added the `public` meta argument. * @since 7.2.0 Added the `required_capabilities` argument. + * @since 7.3.0 Added the `open_world` annotation. * * @see wp_register_ability() * @@ -186,8 +188,9 @@ class WP_Ability { * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. - * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. - * If false, the ability stays within a bounded environment. If null, it is not declared. + * @type bool|null $open_world Optional. If true, the ability may interact with systems outside of the site, + * such as remote HTTP services or email recipients. If false, the ability + * only interacts with the site itself. * } * @type bool $public Optional. Whether the ability is meant to be available * to clients such as the REST API, MCP, or AI agents. @@ -232,6 +235,7 @@ public function __construct( string $name, array $args ) { * @since 6.9.0 * @since 7.1.0 Added the `public` meta argument. * @since 7.2.0 Added the `required_capabilities` argument. + * @since 7.3.0 Added the `open_world` annotation. * * @see WP_Abilities_Registry::register() * @@ -263,8 +267,9 @@ public function __construct( string $name, array $args ) { * If false, the ability performs only additive updates. * @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. - * @type bool|null $open_world Optional. If true, the ability may interact with public or open-ended entities. - * If false, the ability stays within a bounded environment. If null, it is not declared. + * @type bool|null $open_world Optional. If true, the ability may interact with systems outside of the site, + * such as remote HTTP services or email recipients. If false, the ability + * only interacts with the site itself. * } * @type bool $public Optional. Whether the ability is meant to be available * to clients such as the REST API, MCP, or AI agents. @@ -302,8 +307,9 @@ public function __construct( string $name, array $args ) { * If false, the ability performs only additive updates. * @type bool|null $idempotent If true, calling the ability repeatedly with the same arguments * will have no additional effect on its environment. - * @type bool|null $open_world If true, the ability may interact with public or open-ended entities. - * If false, the ability stays within a bounded environment. If null, it is not declared. + * @type bool|null $open_world If true, the ability may interact with systems outside of the site, + * such as remote HTTP services or email recipients. If false, the ability + * only interacts with the site itself. * } * @type bool $public Whether the ability is meant to be available to clients * such as the REST API, MCP, or AI agents. Defaults to diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php index 222a3220d912d..3f2ce73d44289 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php @@ -251,6 +251,7 @@ public function prepare_item_for_response( $ability, $request ) { * @since 6.9.0 * @since 7.1.0 Added the `meta.public` property. * @since 7.2.0 Added the `required_capabilities` property. + * @since 7.3.0 Added the `meta.annotations.open_world` property. * * @return array Item schema data. */ @@ -326,7 +327,7 @@ public function get_item_schema(): array { 'type' => array( 'boolean', 'null' ), ), 'open_world' => array( - 'description' => __( 'Whether the ability may interact with public or open-ended entities.' ), + 'description' => __( 'Whether the ability may interact with systems outside of the site, such as remote HTTP services or email recipients.' ), 'type' => array( 'boolean', 'null' ), ), ), @@ -352,6 +353,7 @@ public function get_item_schema(): array { * @since 6.9.0 * @since 7.1.0 Added the `namespace` and `meta` parameters and the `rest_abilities_collection_params` filter. * @since 7.2.0 Added the `has_required_capabilities` parameter. + * @since 7.3.0 Added the `open_world` annotation filter. * * @return array Collection parameters. */ @@ -405,7 +407,7 @@ public function get_collection_params(): array { 'type' => array( 'boolean', 'null' ), ), 'open_world' => array( - 'description' => __( 'Whether the ability may interact with public or open-ended entities.' ), + 'description' => __( 'Whether the ability may interact with systems outside of the site, such as remote HTTP services or email recipients.' ), 'type' => array( 'boolean', 'null' ), ), ), diff --git a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php index 3d07d4212f28b..bcfb1c5b4bb4d 100644 --- a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php +++ b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php @@ -966,6 +966,63 @@ public function test_filter_by_non_matching_annotation(): void { $this->assertEmpty( $response->get_data() ); } + /** + * Test filtering abilities by the `open_world` annotation. + * + * The value is passed as a string, the way it arrives over the query string, so + * this confirms the meta schema coerces it to a boolean before matching. An + * ability that does not declare the annotation matches neither value. + * + * @ticket 66799 + */ + public function test_filter_by_open_world_annotation(): void { + $abilities = array( + 'test/open-world' => true, + 'test/bounded-world' => false, + 'test/undeclared' => null, + ); + + foreach ( $abilities as $name => $open_world ) { + $meta = array( 'show_in_rest' => true ); + if ( null !== $open_world ) { + $meta['annotations'] = array( 'open_world' => $open_world ); + } + + $this->register_test_ability( + $name, + array( + 'label' => $name, + 'description' => 'Used to test filtering by the open world annotation.', + 'category' => 'general', + 'execute_callback' => '__return_true', + 'permission_callback' => '__return_true', + 'meta' => $meta, + ) + ); + } + + $request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities' ); + $request->set_param( 'meta', array( 'annotations' => array( 'open_world' => 'true' ) ) ); + $request->set_param( 'per_page', 100 ); + $response = $this->server->dispatch( $request ); + + $this->assertSame( 200, $response->get_status() ); + + $names = wp_list_pluck( $response->get_data(), 'name' ); + + $this->assertContains( 'test/open-world', $names, 'An open world ability should match "true".' ); + $this->assertNotContains( 'test/bounded-world', $names, 'A bounded ability should not match "true".' ); + $this->assertNotContains( 'test/undeclared', $names, 'An ability without the annotation should not match "true".' ); + + $request->set_param( 'meta', array( 'annotations' => array( 'open_world' => 'false' ) ) ); + $response = $this->server->dispatch( $request ); + $names = wp_list_pluck( $response->get_data(), 'name' ); + + $this->assertContains( 'test/bounded-world', $names, 'A bounded ability should match "false".' ); + $this->assertNotContains( 'test/open-world', $names, 'An open world ability should not match "false".' ); + $this->assertNotContains( 'test/undeclared', $names, 'An ability without the annotation should not match "false".' ); + } + /** * Test filtering abilities by several meta conditions at once. * diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index d361a954367c4..f1fb83dcacc8c 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -12789,7 +12789,7 @@ mockedApiResponse.Schema = { ] }, "open_world": { - "description": "Whether the ability may interact with public or open-ended entities.", + "description": "Whether the ability may interact with systems outside of the site, such as remote HTTP services or email recipients.", "type": [ "boolean", "null"