From 3b3a0f0a685f435f54d77aa38ab0308902249a00 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Sat, 3 Dec 2016 05:17:26 +0000 Subject: [PATCH] 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. Merge of [39468] to the 4.7 branch. Props peterwilsoncc. Fixes #39005. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@39469 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 20 ++++++++++--------- .../rest-api/rest-settings-controller.php | 16 ++++++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index aa98477417..2ac98bc135 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -1737,16 +1737,18 @@ function register_initial_settings() { 'description' => __( 'Site tagline.' ), ) ); - register_setting( 'general', 'siteurl', array( - 'show_in_rest' => array( - 'name' => 'url', - 'schema' => array( - 'format' => 'uri', + if ( ! is_multisite() ) { + register_setting( 'general', 'siteurl', array( + 'show_in_rest' => array( + 'name' => 'url', + 'schema' => array( + 'format' => 'uri', + ), ), - ), - 'type' => 'string', - 'description' => __( 'Site URL.' ), - ) ); + 'type' => 'string', + 'description' => __( 'Site URL.' ), + ) ); + } register_setting( 'general', 'admin_email', array( 'show_in_rest' => array( diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index ff91a60471..9970e590df 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -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' ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); + $actual = array_keys( $data ); - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( array( + $expected = array( 'title', 'description', 'url', @@ -67,7 +67,17 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase 'posts_per_page', 'default_ping_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() {