Multisite: move get_current_site() to load.php so that it can be used in more places, instead of importing global $current_site.

See #37699.


git-svn-id: https://develop.svn.wordpress.org/trunk@38388 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2016-08-26 21:34:36 +00:00
parent aa2fcba472
commit 55f5577813
6 changed files with 47 additions and 53 deletions

View File

@ -4275,23 +4275,19 @@ 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 ) {
// This is the current network's information; 'site' is old terminology.
global $current_site;
if ( ! is_multisite() )
if ( ! is_multisite() ) {
return true;
}
if ( ! $site_id )
if ( ! $site_id ) {
$site_id = get_current_blog_id();
return (int) $site_id === (int) $current_site->blog_id;
}
return (int) $site_id === (int) get_current_site()->blog_id;
}
/**

View File

@ -3263,13 +3263,15 @@ 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.
@ -3309,13 +3311,15 @@ 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.

View File

@ -1059,3 +1059,22 @@ 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;
}

View File

@ -1083,13 +1083,11 @@ 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 ) {
global $current_site;
$current_site = get_current_site();
if ( empty( $network ) && isset( $current_site ) ) {
$network = $current_site;
}

View File

@ -1332,8 +1332,7 @@ 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, $current_site;
global $wpdb, $wp_roles;
// Cast for security
$blog_id = (int) $blog_id;
@ -1361,7 +1360,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( $current_site->blog_id ), PHP_URL_SCHEME ) ) {
if ( 'https' === parse_url( get_home_url( get_current_site()->blog_id ), PHP_URL_SCHEME ) ) {
$home = set_url_scheme( $home, 'https' );
}
@ -1498,8 +1497,9 @@ 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,25 +1591,6 @@ 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.
*

View File

@ -1070,7 +1070,6 @@ 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.
@ -1078,7 +1077,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, $current_site;
global $wpdb;
if ( $network_id && ! is_numeric( $network_id ) ) {
return false;
@ -1088,7 +1087,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 = $current_site->id;
$network_id = get_current_site()->id;
}
/**
@ -1187,7 +1186,6 @@ 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.
@ -1195,7 +1193,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, $current_site;
global $wpdb;
if ( $network_id && ! is_numeric( $network_id ) ) {
return false;
@ -1205,7 +1203,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 = $current_site->id;
$network_id = get_current_site()->id;
}
wp_protect_special_option( $option );
@ -1297,14 +1295,13 @@ 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, $current_site;
global $wpdb;
if ( $network_id && ! is_numeric( $network_id ) ) {
return false;
@ -1314,7 +1311,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 = $current_site->id;
$network_id = get_current_site()->id;
}
/**
@ -1379,7 +1376,6 @@ 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.
@ -1387,7 +1383,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, $current_site;
global $wpdb;
if ( $network_id && ! is_numeric( $network_id ) ) {
return false;
@ -1397,7 +1393,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 = $current_site->id;
$network_id = get_current_site()->id;
}
wp_protect_special_option( $option );