diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index d16979c9c8fb5..a839ef92966b4 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -834,5 +834,6 @@ 5 ); } +add_filter( 'get_entity_view_config_root_site', '_wp_get_entity_view_config_root_site', 5 ); unset( $filter, $action, $post_type ); diff --git a/src/wp-includes/view-config.php b/src/wp-includes/view-config.php index d972515c12438..8765a5d095008 100644 --- a/src/wp-includes/view-config.php +++ b/src/wp-includes/view-config.php @@ -769,3 +769,36 @@ function _wp_get_entity_view_config_posttype_wp_template( $data ) { return $data; } + +/** + * Provides the view configuration for the `root`/`site` entity. + * + * The site settings are a singleton record edited through a form (the site + * editor's Identity screen) rather than listed in a view, so only the `form` + * is defined here. The generic `default_view`, `default_layouts`, and + * `view_list` built by wp_get_entity_view_config() are left untouched. + * + * @since 7.2.0 + * + * @param WP_View_Config_Data $data The view configuration container for the entity. + * @return WP_View_Config_Data The updated view configuration container. + */ +function _wp_get_entity_view_config_root_site( $data ) { + return $data->set( + array( + 'form' => array( + 'layout' => array( + 'type' => 'regular', + 'labelPosition' => 'top', + ), + 'fields' => array( + 'title', + 'description', + 'site_logo', + 'site_icon', + ), + ), + ), + 1 + ); +} diff --git a/tests/phpunit/tests/rest-api/rest-view-config-controller.php b/tests/phpunit/tests/rest-api/rest-view-config-controller.php index 34fcd55e2466d..c6a7ed86b816d 100644 --- a/tests/phpunit/tests/rest-api/rest-view-config-controller.php +++ b/tests/phpunit/tests/rest-api/rest-view-config-controller.php @@ -302,6 +302,35 @@ public function test_get_items_matches_underlying_config() { $this->assertSame( $config['form'], $data['form'] ); } + /** + * The `root`/`site` entity provides the form of the site identity screen. + * + * @ticket 65981 + * + * @covers ::get_items + */ + public function test_get_items_root_site_form() { + // Admin: reading root config requires `manage_options`. + wp_set_current_user( self::$admin_id ); + + $response = $this->dispatch_request( 'root', 'site' ); + $this->assertSame( 200, $response->get_status() ); + + $data = json_decode( wp_json_encode( $response->get_data() ), true ); + + $this->assertSame( + array( + 'type' => 'regular', + 'labelPosition' => 'top', + ), + $data['form']['layout'] + ); + $this->assertSame( + array( 'title', 'description', 'site_logo', 'site_icon' ), + $data['form']['fields'] + ); + } + /** * Empty object-typed config values serialize as JSON objects ({}), not arrays ([]). *