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
1 change: 1 addition & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
33 changes: 33 additions & 0 deletions src/wp-includes/view-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
29 changes: 29 additions & 0 deletions tests/phpunit/tests/rest-api/rest-view-config-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([]).
*
Expand Down
Loading