REST API: Site URL setting should not be present on multisite installations.

The `siteurl` setting is registered and made available to the REST API. On a multisite installation, this setting is not configurable from the General Settings screen, but due to the above it is configurable from the REST API.

Props peterwilsoncc.
Fixes #39005.



git-svn-id: https://develop.svn.wordpress.org/trunk@39468 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2016-12-03 05:15:42 +00:00
parent 97191393bc
commit 55e972cab3
2 changed files with 24 additions and 12 deletions

View File

@ -1737,16 +1737,18 @@ function register_initial_settings() {
'description' => __( 'Site tagline.' ), 'description' => __( 'Site tagline.' ),
) ); ) );
register_setting( 'general', 'siteurl', array( if ( ! is_multisite() ) {
'show_in_rest' => array( register_setting( 'general', 'siteurl', array(
'name' => 'url', 'show_in_rest' => array(
'schema' => array( 'name' => 'url',
'format' => 'uri', 'schema' => array(
'format' => 'uri',
),
), ),
), 'type' => 'string',
'type' => 'string', 'description' => __( 'Site URL.' ),
'description' => __( 'Site URL.' ), ) );
) ); }
register_setting( 'general', 'admin_email', array( register_setting( 'general', 'admin_email', array(
'show_in_rest' => array( 'show_in_rest' => array(

View File

@ -49,9 +49,9 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
$request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); $request = new WP_REST_Request( 'GET', '/wp/v2/settings' );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();
$actual = array_keys( $data );
$this->assertEquals( 200, $response->get_status() ); $expected = array(
$this->assertEquals( array(
'title', 'title',
'description', 'description',
'url', 'url',
@ -67,7 +67,17 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
'posts_per_page', 'posts_per_page',
'default_ping_status', 'default_ping_status',
'default_comment_status', 'default_comment_status',
), array_keys( $data ) ); );
if ( is_multisite() ) {
$expected = array_diff( $expected, array( 'url' ) );
}
sort( $expected );
sort( $actual );
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( $expected, $actual );
} }
public function test_get_item_value_is_cast_to_type() { public function test_get_item_value_is_cast_to_type() {