diff --git a/src/wp-includes/abilities/wp-core-abilities.php b/src/wp-includes/abilities.php similarity index 85% rename from src/wp-includes/abilities/wp-core-abilities.php rename to src/wp-includes/abilities.php index 610cf68f27c69..de8acdfaab264 100644 --- a/src/wp-includes/abilities/wp-core-abilities.php +++ b/src/wp-includes/abilities.php @@ -8,6 +8,7 @@ */ declare( strict_types = 1 ); + /** * Registers the core ability categories. * @@ -44,16 +45,41 @@ function wp_register_core_abilities(): void { $category_site = 'site'; $category_user = 'user'; - $site_info_fields = array( - 'name', - 'description', - 'url', - 'wpurl', - 'admin_email', - 'charset', - 'language', - 'version', + $site_info_properties = array( + 'name' => array( + 'type' => 'string', + 'description' => __( 'The site title.' ), + ), + 'description' => array( + 'type' => 'string', + 'description' => __( 'The site tagline.' ), + ), + 'url' => array( + 'type' => 'string', + 'description' => __( 'The site home URL.' ), + ), + 'wpurl' => array( + 'type' => 'string', + 'description' => __( 'The WordPress installation URL.' ), + ), + 'admin_email' => array( + 'type' => 'string', + 'description' => __( 'The site administrator email address.' ), + ), + 'charset' => array( + 'type' => 'string', + 'description' => __( 'The site character encoding.' ), + ), + 'language' => array( + 'type' => 'string', + 'description' => __( 'The site language locale code.' ), + ), + 'version' => array( + 'type' => 'string', + 'description' => __( 'The WordPress version.' ), + ), ); + $site_info_fields = array_keys( $site_info_properties ); wp_register_ability( 'core/get-site-info', @@ -78,40 +104,7 @@ function wp_register_core_abilities(): void { ), 'output_schema' => array( 'type' => 'object', - 'properties' => array( - 'name' => array( - 'type' => 'string', - 'description' => __( 'The site title.' ), - ), - 'description' => array( - 'type' => 'string', - 'description' => __( 'The site tagline.' ), - ), - 'url' => array( - 'type' => 'string', - 'description' => __( 'The site home URL.' ), - ), - 'wpurl' => array( - 'type' => 'string', - 'description' => __( 'The WordPress installation URL.' ), - ), - 'admin_email' => array( - 'type' => 'string', - 'description' => __( 'The site administrator email address.' ), - ), - 'charset' => array( - 'type' => 'string', - 'description' => __( 'The site character encoding.' ), - ), - 'language' => array( - 'type' => 'string', - 'description' => __( 'The site language locale code.' ), - ), - 'version' => array( - 'type' => 'string', - 'description' => __( 'The WordPress version.' ), - ), - ), + 'properties' => $site_info_properties, 'additionalProperties' => false, ), 'execute_callback' => static function ( $input = array() ) use ( $site_info_fields ): array { diff --git a/src/wp-settings.php b/src/wp-settings.php index 471c22b0fd7df..20ee50276dad2 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -290,7 +290,7 @@ require ABSPATH . WPINC . '/abilities-api/class-wp-ability.php'; require ABSPATH . WPINC . '/abilities-api/class-wp-abilities-registry.php'; require ABSPATH . WPINC . '/abilities-api.php'; -require ABSPATH . WPINC . '/abilities/wp-core-abilities.php'; +require ABSPATH . WPINC . '/abilities.php'; require ABSPATH . WPINC . '/rest-api.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php'; diff --git a/tests/phpunit/tests/abilities-api/wpCoreAbilities.php b/tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php similarity index 89% rename from tests/phpunit/tests/abilities-api/wpCoreAbilities.php rename to tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php index f87361f0e77f2..c89d6daf32cd6 100644 --- a/tests/phpunit/tests/abilities-api/wpCoreAbilities.php +++ b/tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php @@ -5,9 +5,12 @@ /** * Tests for the core abilities shipped with the Abilities API. * + * @covers wp_register_core_ability_categories + * @covers wp_register_core_abilities + * * @group abilities-api */ -class Tests_Abilities_API_WpCoreAbilities extends WP_UnitTestCase { +class Tests_Abilities_API_WpRegisterCoreAbilities extends WP_UnitTestCase { /** * Set up before the class. @@ -27,10 +30,27 @@ public static function set_up_before_class(): void { add_action( 'wp_abilities_api_init', 'wp_register_core_abilities' ); do_action( 'wp_abilities_api_categories_init' ); do_action( 'wp_abilities_api_init' ); + } + /** + * Tear down after the class. + * + * @since 6.9.0 + */ + public static function tear_down_after_class(): void { // Re-add the unhook functions for subsequent tests. add_action( 'wp_abilities_api_categories_init', '_unhook_core_ability_categories_registration', 1 ); add_action( 'wp_abilities_api_init', '_unhook_core_abilities_registration', 1 ); + + // Remove the core abilities and their categories. + foreach ( wp_get_abilities() as $ability ) { + wp_unregister_ability( $ability->get_name() ); + } + foreach ( wp_get_ability_categories() as $ability_category ) { + wp_unregister_ability_category( $ability_category->get_slug() ); + } + + parent::tear_down_after_class(); } /**