From 58f107fa9583e2be36e6cc3ff178143110f2908a Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Tue, 20 Sep 2016 21:39:29 +0000 Subject: [PATCH] Multisite: Revert [38388]. Restore `get_current_site()` to a multisite only function. Providing this in single site may be a possibility in the future, but should have a dedicated ticket and discussion. See #37699. Built from https://develop.svn.wordpress.org/trunk@38636 git-svn-id: http://core.svn.wordpress.org/trunk@38579 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 16 ++++++++++------ wp-includes/link-template.php | 16 ++++++---------- wp-includes/load.php | 19 ------------------- wp-includes/ms-blogs.php | 4 +++- wp-includes/ms-functions.php | 27 +++++++++++++++++++++++---- wp-includes/option.php | 20 ++++++++++++-------- wp-includes/version.php | 2 +- 7 files changed, 55 insertions(+), 49 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 360a2db83e..48de7e20e1 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4309,19 +4309,23 @@ function wp_suspend_cache_invalidation( $suspend = true ) { * * @since 3.0.0 * + * @global object $current_site + * * @param int $site_id Optional. Site ID to test. Defaults to current site. * @return bool True if $site_id is the main site of the network, or if not * running Multisite. */ function is_main_site( $site_id = null ) { - if ( ! is_multisite() ) { - return true; - } + // This is the current network's information; 'site' is old terminology. + global $current_site; - if ( ! $site_id ) { + if ( ! is_multisite() ) + return true; + + if ( ! $site_id ) $site_id = get_current_blog_id(); - } - return (int) $site_id === (int) get_current_site()->blog_id; + + return (int) $site_id === (int) $current_site->blog_id; } /** diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index c59da22047..b922be0df2 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -3257,15 +3257,13 @@ function network_site_url( $path = '', $scheme = null ) { $current_site = get_current_site(); - if ( 'relative' == $scheme ) { + if ( 'relative' == $scheme ) $url = $current_site->path; - } else { + else $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme ); - } - if ( $path && is_string( $path ) ) { + if ( $path && is_string( $path ) ) $url .= ltrim( $path, '/' ); - } /** * Filters the network site URL. @@ -3305,15 +3303,13 @@ function network_home_url( $path = '', $scheme = null ) { if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; - if ( 'relative' == $scheme ) { + if ( 'relative' == $scheme ) $url = $current_site->path; - } else { + else $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme ); - } - if ( $path && is_string( $path ) ) { + if ( $path && is_string( $path ) ) $url .= ltrim( $path, '/' ); - } /** * Filters the network home URL. diff --git a/wp-includes/load.php b/wp-includes/load.php index fbed09c725..2aa4451067 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -1068,22 +1068,3 @@ function wp_doing_ajax() { function is_wp_error( $thing ) { return ( $thing instanceof WP_Error ); } - -/** - * Get the current network. - * - * Returns an object containing the 'id', 'domain', 'path', and 'site_name' - * properties of the network being viewed. - * - * @see wpmu_current_site() - * - * @since MU - * - * @global WP_Network $current_site - * - * @return WP_Network - */ -function get_current_site() { - global $current_site; - return $current_site; -} diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 51a1ae51b2..84ae7febb9 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -1088,11 +1088,13 @@ function get_networks( $args = array() ) { * * @since 4.6.0 * + * @global WP_Network $current_site + * * @param WP_Network|int|null $network Optional. Network to retrieve. Default is the current network. * @return WP_Network|null The network object or null if not found. */ function get_network( $network = null ) { - $current_site = get_current_site(); + global $current_site; if ( empty( $network ) && isset( $current_site ) ) { $network = $current_site; } diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index 0d97ea77df..113f37f284 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -1332,7 +1332,8 @@ function insert_blog($domain, $path, $site_id) { * @param string $blog_title The title of the new site. */ function install_blog( $blog_id, $blog_title = '' ) { - global $wpdb, $wp_roles; + global $wpdb, $wp_roles, $current_site; + // Cast for security $blog_id = (int) $blog_id; @@ -1360,7 +1361,7 @@ function install_blog( $blog_id, $blog_title = '' ) { if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { $siteurl = set_url_scheme( $siteurl, 'https' ); } - if ( 'https' === parse_url( get_home_url( get_current_site()->blog_id ), PHP_URL_SCHEME ) ) { + if ( 'https' === parse_url( get_home_url( $current_site->blog_id ), PHP_URL_SCHEME ) ) { $home = set_url_scheme( $home, 'https' ); } @@ -1497,9 +1498,8 @@ We hope you enjoy your new site. Thanks! $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; $message = $welcome_email; - if ( empty( $current_site->site_name ) ) { + if ( empty( $current_site->site_name ) ) $current_site->site_name = 'WordPress'; - } /** * Filters the subject of the welcome email after site activation. @@ -1591,6 +1591,25 @@ function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) return true; } +/** + * Get the current network. + * + * Returns an object containing the 'id', 'domain', 'path', and 'site_name' + * properties of the network being viewed. + * + * @see wpmu_current_site() + * + * @since MU + * + * @global WP_Network $current_site + * + * @return WP_Network + */ +function get_current_site() { + global $current_site; + return $current_site; +} + /** * Get a user's most recent post. * diff --git a/wp-includes/option.php b/wp-includes/option.php index ff373cbf04..2293b0154f 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -1070,6 +1070,7 @@ function update_site_option( $option, $value ) { * @see get_option() * * @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. @@ -1077,7 +1078,7 @@ function update_site_option( $option, $value ) { * @return mixed Value set for the option. */ function get_network_option( $network_id, $option, $default = false ) { - global $wpdb; + global $wpdb, $current_site; if ( $network_id && ! is_numeric( $network_id ) ) { return false; @@ -1087,7 +1088,7 @@ function get_network_option( $network_id, $option, $default = false ) { // Fallback to the current network if a network ID is not specified. if ( ! $network_id && is_multisite() ) { - $network_id = get_current_site()->id; + $network_id = $current_site->id; } /** @@ -1186,6 +1187,7 @@ function get_network_option( $network_id, $option, $default = false ) { * @see add_option() * * @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 add. Expected to not be SQL-escaped. @@ -1193,7 +1195,7 @@ function get_network_option( $network_id, $option, $default = false ) { * @return bool False if option was not added and true if option was added. */ function add_network_option( $network_id, $option, $value ) { - global $wpdb; + global $wpdb, $current_site; if ( $network_id && ! is_numeric( $network_id ) ) { return false; @@ -1203,7 +1205,7 @@ function add_network_option( $network_id, $option, $value ) { // Fallback to the current network if a network ID is not specified. if ( ! $network_id && is_multisite() ) { - $network_id = get_current_site()->id; + $network_id = $current_site->id; } wp_protect_special_option( $option ); @@ -1295,13 +1297,14 @@ function add_network_option( $network_id, $option, $value ) { * @see delete_option() * * @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 remove. Expected to not be SQL-escaped. * @return bool True, if succeed. False, if failure. */ function delete_network_option( $network_id, $option ) { - global $wpdb; + global $wpdb, $current_site; if ( $network_id && ! is_numeric( $network_id ) ) { return false; @@ -1311,7 +1314,7 @@ function delete_network_option( $network_id, $option ) { // Fallback to the current network if a network ID is not specified. if ( ! $network_id && is_multisite() ) { - $network_id = get_current_site()->id; + $network_id = $current_site->id; } /** @@ -1376,6 +1379,7 @@ function delete_network_option( $network_id, $option ) { * @see update_option() * * @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. @@ -1383,7 +1387,7 @@ function delete_network_option( $network_id, $option ) { * @return bool False if value was not updated and true if value was updated. */ function update_network_option( $network_id, $option, $value ) { - global $wpdb; + global $wpdb, $current_site; if ( $network_id && ! is_numeric( $network_id ) ) { return false; @@ -1393,7 +1397,7 @@ function update_network_option( $network_id, $option, $value ) { // Fallback to the current network if a network ID is not specified. if ( ! $network_id && is_multisite() ) { - $network_id = get_current_site()->id; + $network_id = $current_site->id; } wp_protect_special_option( $option ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 7fdece3f85..ed4d57a837 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38635'; +$wp_version = '4.7-alpha-38636'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.