Use get_current_site() instead of the $current_site global when possible.

props jeremyfelt.
fixes #25158.

git-svn-id: https://develop.svn.wordpress.org/trunk@26120 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2013-11-13 03:22:48 +00:00
parent f13e9a6796
commit 39d55fddb8
16 changed files with 54 additions and 58 deletions

View File

@@ -243,8 +243,6 @@ function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
* @param WP_Admin_Bar $wp_admin_bar
*/
function wp_admin_bar_site_menu( $wp_admin_bar ) {
global $current_site;
// Don't show for logged out users.
if ( ! is_user_logged_in() )
return;
@@ -259,9 +257,9 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) {
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
if ( is_network_admin() ) {
$blogname = sprintf( __('Network Admin: %s'), esc_html( $current_site->site_name ) );
$blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) );
} elseif ( is_user_admin() ) {
$blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );
$blogname = sprintf( __('Global Dashboard: %s'), esc_html( get_current_site()->site_name ) );
}
$title = wp_html_excerpt( $blogname, 40, '…' );

View File

@@ -459,7 +459,6 @@ class wp_xmlrpc_server extends IXR_Server {
* - 'xmlrpc' - url of xmlrpc endpoint
*/
function wp_getUsersBlogs( $args ) {
global $current_site;
// If this isn't on WPMU then just use blogger_getUsersBlogs
if ( !is_multisite() ) {
array_unshift( $args, 1 );
@@ -481,7 +480,7 @@ class wp_xmlrpc_server extends IXR_Server {
foreach ( $blogs as $blog ) {
// Don't include blogs that aren't hosted at this site
if ( $blog->site_id != $current_site->id )
if ( $blog->site_id != get_current_site()->id )
continue;
$blog_id = $blog->userblog_id;

View File

@@ -545,11 +545,11 @@ function allowed_http_request_hosts( $is_external, $host ) {
* @return bool
*/
function ms_allowed_http_request_hosts( $is_external, $host ) {
global $wpdb, $current_site;
global $wpdb;
static $queried = array();
if ( $is_external )
return $is_external;
if ( $host === $current_site->domain )
if ( $host === get_current_site()->domain )
return true;
if ( isset( $queried[ $host ] ) )
return $queried[ $host ];

View File

@@ -2187,11 +2187,11 @@ function plugins_url($path = '', $plugin = '') {
* @return string Site url link with optional path appended.
*/
function network_site_url( $path = '', $scheme = null ) {
global $current_site;
if ( ! is_multisite() )
return site_url($path, $scheme);
$current_site = get_current_site();
if ( 'relative' == $scheme )
$url = $current_site->path;
else
@@ -2218,11 +2218,10 @@ function network_site_url( $path = '', $scheme = null ) {
* @return string Home url link with optional path appended.
*/
function network_home_url( $path = '', $scheme = null ) {
global $current_site;
if ( ! is_multisite() )
return home_url($path, $scheme);
$current_site = get_current_site();
$orig_scheme = $scheme;
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )

View File

@@ -64,8 +64,9 @@ function get_blogaddress_by_name( $blogname ) {
* @return int A blog id
*/
function get_id_from_blogname( $slug ) {
global $wpdb, $current_site;
global $wpdb;
$current_site = get_current_site();
$slug = trim( $slug, '/' );
$blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );

View File

@@ -45,7 +45,7 @@ function ms_upload_constants() {
* @since 3.0.0
*/
function ms_cookie_constants( ) {
global $current_site;
$current_site = get_current_site();
/**
* @since 1.2.0

View File

@@ -535,9 +535,10 @@ function wpmu_validate_user_signup($user_name, $user_email) {
* @param string $blog_title The blog title provided by the user.
* @return array Contains the new site data and error messages.
*/
function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {
global $wpdb, $domain, $current_site;
function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) {
global $wpdb, $domain;
$current_site = get_current_site();
$base = $current_site->path;
$blog_title = strip_tags( $blog_title );
@@ -709,13 +710,11 @@ function wpmu_signup_user( $user, $user_email, $meta = array() ) {
* @return bool
*/
function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta = array() ) {
global $current_site;
if ( !apply_filters('wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta) )
return false;
// Send email with activation link.
if ( !is_subdomain_install() || $current_site->id != 1 )
if ( !is_subdomain_install() || get_current_site()->id != 1 )
$activate_url = network_site_url("wp-activate.php?key=$key");
else
$activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API
@@ -1122,8 +1121,8 @@ function insert_blog($domain, $path, $site_id) {
* @param int $blog_id The value returned by insert_blog().
* @param string $blog_title The title of the new site.
*/
function install_blog($blog_id, $blog_title = '') {
global $wpdb, $wp_roles, $current_site;
function install_blog( $blog_id, $blog_title = '' ) {
global $wpdb, $wp_roles;
// Cast for security
$blog_id = (int) $blog_id;
@@ -1151,7 +1150,7 @@ function install_blog($blog_id, $blog_title = '') {
if ( get_site_option( 'ms_files_rewriting' ) )
update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );
else
update_option( 'upload_path', get_blog_option( $current_site->blog_id, 'upload_path' ) );
update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) );
update_option( 'blogname', wp_unslash( $blog_title ) );
update_option( 'admin_email', '' );
@@ -1205,7 +1204,7 @@ function install_blog_defaults($blog_id, $user_id) {
* @return bool
*/
function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
global $current_site;
$current_site = get_current_site();
if ( !apply_filters('wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta) )
return false;
@@ -1269,7 +1268,7 @@ We hope you enjoy your new site. Thanks!
* @return bool
*/
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
global $current_site;
$current_site = get_current_site();
if ( !apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta) )
return false;
@@ -1560,8 +1559,7 @@ function global_terms( $term_id, $deprecated = '' ) {
* @return array The current site's domain
*/
function redirect_this_site( $deprecated = '' ) {
global $current_site;
return array( $current_site->domain );
return array( get_current_site()->domain );
}
/**
@@ -1689,11 +1687,10 @@ function add_existing_user_to_blog( $details = false ) {
* @param array $meta
*/
function add_new_user_to_blog( $user_id, $password, $meta ) {
global $current_site;
if ( !empty( $meta[ 'add_to_blog' ] ) ) {
$blog_id = $meta[ 'add_to_blog' ];
$role = $meta[ 'new_role' ];
remove_user_from_blog($user_id, $current_site->blog_id); // remove user from main blog.
remove_user_from_blog($user_id, get_current_site()->blog_id); // remove user from main blog.
add_user_to_blog( $blog_id, $user_id, $role );
update_user_meta( $user_id, 'primary_blog', $blog_id );
}
@@ -1705,8 +1702,7 @@ function add_new_user_to_blog( $user_id, $password, $meta ) {
* @since MU
*/
function fix_phpmailer_messageid( $phpmailer ) {
global $current_site;
$phpmailer->Hostname = $current_site->domain;
$phpmailer->Hostname = get_current_site()->domain;
}
/**

View File

@@ -71,8 +71,6 @@ function wp_get_active_network_plugins() {
* @return bool|string Returns true on success, or drop-in file to include.
*/
function ms_site_check() {
global $wpdb, $current_site;
$blog = get_blog_details();
/**
@@ -101,7 +99,7 @@ function ms_site_check() {
if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
return WP_CONTENT_DIR . '/blog-inactive.php';
else
wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) );
wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_current_site()->domain ) ) ) );
}
if ( $blog->archived == '1' || $blog->spam == '1' ) {