Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

declare( strict_types = 1 );

/**
* Registers the core ability categories.
*
Expand Down Expand Up @@ -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',
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}

/**
Expand Down
Loading