From 55122c1538f7ccc45d3135b201c9e65819b6c1f0 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Sun, 11 Oct 2015 22:43:59 +0000 Subject: [PATCH] MS: Adjust `_network_option()` parameter order, `$network_id` is first. This better aligns with expectations and matches the structure used by `_blog_option()`. The `_site_option()` functions remain as an appropriate method for working with the current network. See #28290. git-svn-id: https://develop.svn.wordpress.org/trunk@35024 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-network.php | 2 +- src/wp-includes/ms-functions.php | 2 +- src/wp-includes/option.php | 36 ++++++++++---------- tests/phpunit/tests/option/networkOption.php | 16 ++++----- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/wp-includes/class-wp-network.php b/src/wp-includes/class-wp-network.php index cb80ead944..a60c1ae223 100644 --- a/src/wp-includes/class-wp-network.php +++ b/src/wp-includes/class-wp-network.php @@ -145,7 +145,7 @@ class WP_Network { } $default = ucfirst( $this->domain ); - $this->site_name = get_network_option( 'site_name', $default, $this->id ); + $this->site_name = get_network_option( $this->id, 'site_name', $default ); } /** diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index dc92eb3cbd..2e67a3cfa3 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -1343,7 +1343,7 @@ function install_blog( $blog_id, $blog_title = '' ) { if ( ! is_subdomain_install() ) { - if ( 'https' === parse_url( get_network_option( 'siteurl' ), PHP_URL_SCHEME ) ) { + if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { $siteurl = set_url_scheme( $siteurl, 'https' ); } if ( 'https' === parse_url( get_home_url( $current_site->blog_id ), PHP_URL_SCHEME ) ) { diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 562438743a..5d3e6fe8ef 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -999,7 +999,7 @@ function delete_all_user_settings() { * @return mixed Value set for the option. */ function get_site_option( $option, $default = false, $deprecated = true ) { - return get_network_option( $option, $default ); + return get_network_option( null, $option, $default ); } /** @@ -1017,7 +1017,7 @@ function get_site_option( $option, $default = false, $deprecated = true ) { * @return bool False if the option was not added. True if the option was added. */ function add_site_option( $option, $value ) { - return add_network_option( $option, $value ); + return add_network_option( null, $option, $value ); } /** @@ -1032,7 +1032,7 @@ function add_site_option( $option, $value ) { * @return bool True, if succeed. False, if failure. */ function delete_site_option( $option ) { - return delete_network_option( $option ); + return delete_network_option( null, $option ); } /** @@ -1048,7 +1048,7 @@ function delete_site_option( $option ) { * @return bool False if value was not updated. True if value was updated. */ function update_site_option( $option, $value ) { - return update_network_option( $option, $value ); + return update_network_option( null, $option, $value ); } /** @@ -1061,12 +1061,12 @@ function update_site_option( $option, $value ) { * @global wpdb $wpdb * @global object $current_site * + * @param int $network_id ID of the network. Can be null to default to the current network ID. * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. * @param mixed $default Optional. Value to return if the option doesn't exist. Default false. - * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID. * @return mixed Value set for the option. */ -function get_network_option( $option, $default = false, $network_id = false ) { +function get_network_option( $network_id, $option, $default = false ) { global $wpdb, $current_site; $network_id = (int) $network_id; @@ -1174,12 +1174,12 @@ function get_network_option( $option, $default = false, $network_id = false ) { * @global wpdb $wpdb * @global object $current_site * - * @param string $option Name of option to add. Expected to not be SQL-escaped. - * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. - * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID. + * @param int $network_id ID of the network. Can be null to default to the current network ID. + * @param string $option Name of option to add. Expected to not be SQL-escaped. + * @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. * @return bool False if option was not added and true if option was added. */ -function add_network_option( $option, $value, $network_id = false ) { +function add_network_option( $network_id, $option, $value ) { global $wpdb, $current_site; $network_id = (int) $network_id; @@ -1215,7 +1215,7 @@ function add_network_option( $option, $value, $network_id = false ) { // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { - if ( false !== get_network_option( $option, false, $network_id ) ) { + if ( false !== get_network_option( $network_id, $option, false ) ) { return false; } } @@ -1280,11 +1280,11 @@ function add_network_option( $option, $value, $network_id = false ) { * @global wpdb $wpdb * @global object $current_site * - * @param string $option Name of option to remove. Expected to not be SQL-escaped. - * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID. + * @param int $network_id ID of the network. Can be null to default to the current network ID. + * @param string $option Name of option to remove. Expected to not be SQL-escaped. * @return bool True, if succeed. False, if failure. */ -function delete_network_option( $option, $network_id = false ) { +function delete_network_option( $network_id, $option ) { global $wpdb, $current_site; $network_id = (int) $network_id; @@ -1358,12 +1358,12 @@ function delete_network_option( $option, $network_id = false ) { * @global wpdb $wpdb * @global object $current_site * + * @param int $network_id ID of the network. Can be null to default to the current network ID. * @param string $option Name of option. Expected to not be SQL-escaped. * @param mixed $value Option value. Expected to not be SQL-escaped. - * @param int|bool $network_id Optional. ID of the network. Defaults to current network ID. * @return bool False if value was not updated and true if value was updated. */ -function update_network_option( $option, $value, $network_id = false ) { +function update_network_option( $network_id, $option, $value ) { global $wpdb, $current_site; $network_id = (int) $network_id; @@ -1375,7 +1375,7 @@ function update_network_option( $option, $value, $network_id = false ) { wp_protect_special_option( $option ); - $old_value = get_network_option( $option, false, $network_id ); + $old_value = get_network_option( $network_id, $option, false ); /** * Filter a specific network option before its value is updated. @@ -1397,7 +1397,7 @@ function update_network_option( $option, $value, $network_id = false ) { } if ( false === $old_value ) { - return add_network_option( $option, $value, $network_id ); + return add_network_option( $network_id, $option, $value ); } $notoptions_key = "$network_id:notoptions"; diff --git a/tests/phpunit/tests/option/networkOption.php b/tests/phpunit/tests/option/networkOption.php index 8eb9ec0199..c8133cbab4 100644 --- a/tests/phpunit/tests/option/networkOption.php +++ b/tests/phpunit/tests/option/networkOption.php @@ -15,8 +15,8 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase { $option = rand_str(); $value = rand_str(); - add_network_option( $option, $value ); - $this->assertFalse( get_network_option( $option, false, $id ) ); + add_site_option( $option, $value ); + $this->assertFalse( get_network_option( $id, $option, false ) ); } function test_add_network_option_available_on_same_network() { @@ -24,8 +24,8 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase { $option = rand_str(); $value = rand_str(); - add_network_option( $option, $value, $id ); - $this->assertEquals( $value, get_network_option( $option, false, $id ) ); + add_network_option( $id, $option, $value ); + $this->assertEquals( $value, get_network_option( $id, $option, false ) ); } function test_delete_network_option_on_only_one_network() { @@ -33,10 +33,10 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase { $option = rand_str(); $value = rand_str(); - add_network_option( $option, $value ); - add_network_option( $option, $value, $id ); - delete_network_option( $option ); - $this->assertEquals( $value, get_network_option( $option, false, $id ) ); + add_site_option( $option, $value ); + add_network_option( $id, $option, $value ); + delete_site_option( $option ); + $this->assertEquals( $value, get_network_option( $id, $option, false ) ); } }