Make WordPress Core

Changeset 61068


Ignore:
Timestamp:
10/27/2025 09:06:15 AM (10 months ago)
Author:
gziolo
Message:

Abilities API: Refactor registration for core abilities

Renames the files and adds a test cleanup so it doesn't accidentaly influence the rest of other tests.

Developed in https://github.com/WordPress/wordpress-develop/pull/10423.

Follow-up [61063].
See #64146.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/abilities/wp-core-abilities.php

    r61063 r61068  
    99
    1010declare( strict_types = 1 );
     11
    1112/**
    1213 * Registers the core ability categories.
     
    4546        $category_user = 'user';
    4647
    47         $site_info_fields = array(
    48                 'name',
    49                 'description',
    50                 'url',
    51                 'wpurl',
    52                 'admin_email',
    53                 'charset',
    54                 'language',
    55                 'version',
    56         );
     48        $site_info_properties = array(
     49                'name'        => array(
     50                        'type'        => 'string',
     51                        'description' => __( 'The site title.' ),
     52                ),
     53                'description' => array(
     54                        'type'        => 'string',
     55                        'description' => __( 'The site tagline.' ),
     56                ),
     57                'url'         => array(
     58                        'type'        => 'string',
     59                        'description' => __( 'The site home URL.' ),
     60                ),
     61                'wpurl'       => array(
     62                        'type'        => 'string',
     63                        'description' => __( 'The WordPress installation URL.' ),
     64                ),
     65                'admin_email' => array(
     66                        'type'        => 'string',
     67                        'description' => __( 'The site administrator email address.' ),
     68                ),
     69                'charset'     => array(
     70                        'type'        => 'string',
     71                        'description' => __( 'The site character encoding.' ),
     72                ),
     73                'language'    => array(
     74                        'type'        => 'string',
     75                        'description' => __( 'The site language locale code.' ),
     76                ),
     77                'version'     => array(
     78                        'type'        => 'string',
     79                        'description' => __( 'The WordPress version.' ),
     80                ),
     81        );
     82        $site_info_fields = array_keys( $site_info_properties );
    5783
    5884        wp_register_ability(
     
    79105                        'output_schema'       => array(
    80106                                'type'                 => 'object',
    81                                 'properties'           => array(
    82                                         'name'        => array(
    83                                                 'type'        => 'string',
    84                                                 'description' => __( 'The site title.' ),
    85                                         ),
    86                                         'description' => array(
    87                                                 'type'        => 'string',
    88                                                 'description' => __( 'The site tagline.' ),
    89                                         ),
    90                                         'url'         => array(
    91                                                 'type'        => 'string',
    92                                                 'description' => __( 'The site home URL.' ),
    93                                         ),
    94                                         'wpurl'       => array(
    95                                                 'type'        => 'string',
    96                                                 'description' => __( 'The WordPress installation URL.' ),
    97                                         ),
    98                                         'admin_email' => array(
    99                                                 'type'        => 'string',
    100                                                 'description' => __( 'The site administrator email address.' ),
    101                                         ),
    102                                         'charset'     => array(
    103                                                 'type'        => 'string',
    104                                                 'description' => __( 'The site character encoding.' ),
    105                                         ),
    106                                         'language'    => array(
    107                                                 'type'        => 'string',
    108                                                 'description' => __( 'The site language locale code.' ),
    109                                         ),
    110                                         'version'     => array(
    111                                                 'type'        => 'string',
    112                                                 'description' => __( 'The WordPress version.' ),
    113                                         ),
    114                                 ),
     107                                'properties'           => $site_info_properties,
    115108                                'additionalProperties' => false,
    116109                        ),
  • trunk/src/wp-settings.php

    r61063 r61068  
    291291require ABSPATH . WPINC . '/abilities-api/class-wp-abilities-registry.php';
    292292require ABSPATH . WPINC . '/abilities-api.php';
    293 require ABSPATH . WPINC . '/abilities/wp-core-abilities.php';
     293require ABSPATH . WPINC . '/abilities.php';
    294294require ABSPATH . WPINC . '/rest-api.php';
    295295require ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php';
  • trunk/tests/phpunit/tests/abilities-api/wpCoreAbilities.php

    r61063 r61068  
    66 * Tests for the core abilities shipped with the Abilities API.
    77 *
     8 * @covers wp_register_core_ability_categories
     9 * @covers wp_register_core_abilities
     10 *
    811 * @group abilities-api
    912 */
    10 class Tests_Abilities_API_WpCoreAbilities extends WP_UnitTestCase {
     13class Tests_Abilities_API_WpRegisterCoreAbilities extends WP_UnitTestCase {
    1114
    1215        /**
     
    2831                do_action( 'wp_abilities_api_categories_init' );
    2932                do_action( 'wp_abilities_api_init' );
     33        }
    3034
     35        /**
     36         * Tear down after the class.
     37         *
     38         * @since 6.9.0
     39         */
     40        public static function tear_down_after_class(): void {
    3141                // Re-add the unhook functions for subsequent tests.
    3242                add_action( 'wp_abilities_api_categories_init', '_unhook_core_ability_categories_registration', 1 );
    3343                add_action( 'wp_abilities_api_init', '_unhook_core_abilities_registration', 1 );
     44
     45                // Remove the core abilities and their categories.
     46                foreach ( wp_get_abilities() as $ability ) {
     47                        wp_unregister_ability( $ability->get_name() );
     48                }
     49                foreach ( wp_get_ability_categories() as $ability_category ) {
     50                        wp_unregister_ability_category( $ability_category->get_slug() );
     51                }
     52
     53                parent::tear_down_after_class();
    3454        }
    3555
Note: See TracChangeset for help on using the changeset viewer.