Ticket #65569: 65569-optional-category-uncategorized.diff
| File 65569-optional-category-uncategorized.diff, 7.8 KB (added by , 2 months ago) |
|---|
-
src/wp-includes/abilities-api/class-wp-abilities-registry.php
diff --git a/src/wp-includes/abilities-api/class-wp-abilities-registry.php b/src/wp-includes/abilities-api/class-wp-abilities-registry.php
a b final class WP_Abilities_Registry { 94 94 * @type string $description The detailed description of what the ability does. 95 95 * @type string $input_schema The schema of the input data. Default empty array. 96 96 * @type string $output_schema The schema of the output data. Default empty array. 97 * @type string $category The ability category slug this ability belongs to. 97 * @type string $category Optional. The ability category slug this ability 98 * belongs to. Defaults to `uncategorized`. 98 99 * @type callable $permission_callback The callback used to check if the current user can perform the ability. 99 100 * @type callable $execute_callback The callback used to perform the ability. 100 101 * @type array $meta Optional metadata for the ability. Default empty array. … … final class WP_Abilities_Registry { 198 199 * @type string $description The detailed description of what the ability does. 199 200 * @type string $input_schema The schema of the input data. Default empty array. 200 201 * @type string $output_schema The schema of the output data. Default empty array. 201 * @type string $category The ability category slug this ability belongs to. 202 * @type string $category Optional. The ability category slug this ability 203 * belongs to. Defaults to `uncategorized`. 202 204 * @type callable $permission_callback The callback used to check if the current user can perform the ability. 203 205 * @type callable $execute_callback The callback used to perform the ability. 204 206 * @type array $meta Optional metadata for the ability. Default empty array. … … final class WP_Abilities_Registry { 228 230 229 231 $args = apply_filters( 'wp_register_ability_args', $args, $name ); 230 232 231 // Validate ability category exists if provided (will be validated as required in WP_Ability). 233 if ( empty( $args['category'] ) ) { 234 $args['category'] = 'uncategorized'; 235 } 236 237 // Validate ability category exists after applying the default. 232 238 if ( isset( $args['category'] ) ) { 233 239 $category = $this->get_registered_category( $args['category'] ); 234 240 -
src/wp-includes/abilities-api.php
diff --git a/src/wp-includes/abilities-api.php b/src/wp-includes/abilities-api.php
a b function wp_abilities_api_init() { 2050 2050 * Registers a new ability. 2051 2051 * 2052 2052 * An ability is a specific piece of functionality that can be registered and executed within WordPress. 2053 * Abilities can be organized into categories which must be registered before abilities that reference them. 2053 * Abilities can be organized into categories. If no category is provided, the ability is assigned to the 2054 * built-in `uncategorized` category. Custom categories must be registered before abilities that reference them. 2054 2055 * 2055 2056 * This function should be called on the {@see 'wp_abilities_api_init'} action hook. 2056 2057 * The ability name must be in the format `namespace/name` and can contain lowercase alphanumeric 2057 2058 * characters, dashes, and underscores. Abilities will not be registered if the ability name is not unique, 2058 * if a c ategory is specified but not registered, or if the ability data is invalid.2059 * if a custom category is specified but not registered, or if the ability data is invalid. 2059 2060 * 2060 2061 * wp_register_ability( 'myplugin/hello-world', array( 2061 2062 * 'label' => __( 'Hello World', 'myplugin' ), … … function wp_abilities_api_init() { 2072 2073 * @type string $description The detailed description of what the ability does. 2073 2074 * @type array $input_schema The schema of the input data. Default empty array. 2074 2075 * @type array $output_schema The schema of the output data. Default empty array. 2075 * @type string $category The ability category slug this ability belongs to. The category 2076 * must be registered using {@see wp_register_ability_category()}. 2076 * @type string $category Optional. The ability category slug this ability belongs to. 2077 * Defaults to `uncategorized`. Custom categories must be registered 2078 * using {@see wp_register_ability_category()}. 2077 2079 * @type callable $permission_callback The callback used to check if the current user can perform the ability. 2078 2080 * @type callable $execute_callback The callback used to perform the ability. 2079 2081 * @type array $meta Optional metadata for the ability. Default empty array. … … function wp_unregister_ability( string $name ): bool { 2234 2236 * 2235 2237 * Ability categories are used to group related abilities together. Categories must be registered before 2236 2238 * abilities that reference them are registered. Core provides built-in categories for common use cases. 2237 * Plugin and theme developers can register their own categories to organize their abilities. 2239 * Plugin and theme developers can register their own categories to organize their abilities. Abilities that 2240 * omit a category are assigned to the built-in `uncategorized` category, which is intended as an escape hatch 2241 * for simple or transitional registrations. 2238 2242 * 2239 2243 * This function should be called on the {@see 'wp_abilities_api_categories_init'} action hook. 2240 2244 * The category slug must be unique and can contain lowercase alphanumeric characters, dashes, and underscores. -
src/wp-includes/abilities.php
diff --git a/src/wp-includes/abilities.php b/src/wp-includes/abilities.php
a b function wp_register_core_ability_categories(): void { 995 995 ) 996 996 ); 997 998 wp_register_ability_category( 999 'uncategorized', 1000 array( 1001 'label' => __( 'Uncategorized' ), 1002 'description' => __( 'Abilities that have not been assigned to a specific category.' ), 1003 ) 1004 ); 997 1005 } 998 1006 999 1007 /** 1000 1008 -
tests/phpunit/tests/abilities-api/wpRegisterAbility.php
diff --git a/tests/phpunit/tests/abilities-api/wpRegisterAbility.php b/tests/phpunit/tests/abilities-api/wpRegisterAbility.php
a b class Tests_Abilities_API_wpRegisterAbility extends WP_UnitTestCase { 117 117 $this->assertSame( 'Test ability description.', $ability->get_description() ); 118 118 } 119 120 /** 121 * @ticket 65569 122 */ 123 public function test_register_ability_without_category_uses_uncategorized_category(): void { 124 global $wp_current_filter; 125 126 $wp_current_filter[] = 'wp_abilities_api_categories_init'; 127 wp_register_ability_category( 128 'uncategorized', 129 array( 130 'label' => 'Uncategorized', 131 'description' => 'Abilities that have not been assigned to a specific category.', 132 ) 133 ); 134 array_pop( $wp_current_filter ); 135 136 $ability = wp_register_ability( 137 'test/without-category', 138 array( 139 'label' => 'Test ability without category', 140 'description' => 'Test ability description.', 141 'input_schema' => array(), 142 'output_schema' => array(), 143 'permission_callback' => '__return_true', 144 'execute_callback' => static function (): array { 145 return array( 'success' => true ); 146 }, 147 ) 148 ); 149 150 $this->assertInstanceOf( WP_Ability::class, $ability ); 151 $this->assertSame( 'uncategorized', $ability->get_category() ); 152 153 wp_unregister_ability_category( 'uncategorized' ); 154 } 119 155 120 156 /** 121 157 * @ticket 64098
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)