Skip to content

Commit

Permalink
Use get_current_site() instead of the $current_site global when possi…
Browse files Browse the repository at this point in the history
…ble.

props jeremyfelt.
fixes #25158.
Built from https://develop.svn.wordpress.org/trunk@26120


git-svn-id: http://core.svn.wordpress.org/trunk@26032 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Nov 13, 2013
1 parent fdc8f7d commit 74f77b8
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 58 deletions.
4 changes: 3 additions & 1 deletion wp-admin/admin-header.php
Expand Up @@ -12,7 +12,9 @@

// In case admin-header.php is included in a function.
global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $wp_version,
$current_site, $update_title, $total_update_count, $parent_file;
$update_title, $total_update_count, $parent_file;

$current_site = get_current_site();

// Catch plugins that include admin-header.php before admin.php completes.
if ( empty( $current_screen ) )
Expand Down
10 changes: 6 additions & 4 deletions wp-admin/includes/class-wp-ms-sites-list-table.php
Expand Up @@ -21,7 +21,9 @@ function ajax_user_can() {
}

function prepare_items() {
global $s, $mode, $wpdb, $current_site;
global $s, $mode, $wpdb;

$current_site = get_current_site();

$mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];

Expand Down Expand Up @@ -168,7 +170,7 @@ function get_sortable_columns() {
}

function display_rows() {
global $current_site, $mode;
global $mode;

$status_list = array(
'archived' => array( 'site-archived', __( 'Archived' ) ),
Expand Down Expand Up @@ -202,7 +204,7 @@ function display_rows() {
}
echo "<tr class='$class'>";

$blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
$blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path'];

list( $columns, $hidden ) = $this->get_column_info();

Expand Down Expand Up @@ -251,7 +253,7 @@ function display_rows() {

$actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
$actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
if ( $current_site->blog_id != $blog['blog_id'] ) {
if ( get_current_site()->blog_id != $blog['blog_id'] ) {
if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
$actions['activate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>';
else
Expand Down
4 changes: 2 additions & 2 deletions wp-admin/includes/class-wp-ms-users-list-table.php
Expand Up @@ -133,7 +133,7 @@ function get_sortable_columns() {
}

function display_rows() {
global $current_site, $mode;
global $mode;

$alt = '';
$super_admins = get_super_admins();
Expand Down Expand Up @@ -223,7 +223,7 @@ function display_rows() {

$path = ( $val->path == '/' ) ? '' : $val->path;
echo '<span class="site-' . $val->site_id . '" >';
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
echo ' <small class="row-actions">';
$actions = array();
$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
Expand Down
4 changes: 3 additions & 1 deletion wp-admin/includes/ms.php
Expand Up @@ -52,7 +52,7 @@ function check_upload_size( $file ) {
* @return void
*/
function wpmu_delete_blog( $blog_id, $drop = false ) {
global $wpdb, $current_site;
global $wpdb;

$switch = false;
if ( get_current_blog_id() != $blog_id ) {
Expand Down Expand Up @@ -82,6 +82,8 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {

update_blog_status( $blog_id, 'deleted', 1 );

$current_site = get_current_site();

// Don't destroy the initial, main, or root blog.
if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
$drop = false;
Expand Down
4 changes: 2 additions & 2 deletions wp-admin/includes/schema.php
Expand Up @@ -327,7 +327,7 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
* @uses $wp_db_version
*/
function populate_options() {
global $wpdb, $wp_db_version, $current_site, $wp_current_db_version;
global $wpdb, $wp_db_version, $wp_current_db_version;

$guessurl = wp_guess_url();
/**
Expand Down Expand Up @@ -495,7 +495,7 @@ function populate_options() {
// 3.0 multisite
if ( is_multisite() ) {
/* translators: blog tagline */
$options[ 'blogdescription' ] = sprintf(__('Just another %s site'), $current_site->site_name );
$options[ 'blogdescription' ] = sprintf(__('Just another %s site'), get_current_site()->site_name );
$options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/';
}

Expand Down
6 changes: 3 additions & 3 deletions wp-admin/includes/upgrade.php
Expand Up @@ -100,8 +100,8 @@ function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated
*
* @param int $user_id User ID.
*/
function wp_install_defaults($user_id) {
global $wpdb, $wp_rewrite, $current_site, $table_prefix;
function wp_install_defaults( $user_id ) {
global $wpdb, $wp_rewrite, $table_prefix;

// Default category
$cat_name = __('Uncategorized');
Expand Down Expand Up @@ -135,7 +135,7 @@ function wp_install_defaults($user_id) {
$first_post = __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' );

$first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post );
$first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post );
$first_post = str_replace( "SITE_NAME", get_current_site()->site_name, $first_post );
} else {
$first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
}
Expand Down
6 changes: 2 additions & 4 deletions wp-includes/admin-bar.php
Expand Up @@ -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;
Expand All @@ -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, '&hellip;' );
Expand Down
3 changes: 1 addition & 2 deletions wp-includes/class-wp-xmlrpc-server.php
Expand Up @@ -459,7 +459,6 @@ function initialise_blog_option_info() {
* - '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 );
Expand All @@ -481,7 +480,7 @@ function wp_getUsersBlogs( $args ) {

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;
Expand Down
4 changes: 2 additions & 2 deletions wp-includes/http.php
Expand Up @@ -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 ];
Expand Down
7 changes: 3 additions & 4 deletions wp-includes/link-template.php
Expand Up @@ -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
Expand All @@ -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' ) ) )
Expand Down
3 changes: 2 additions & 1 deletion wp-includes/ms-blogs.php
Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/ms-default-constants.php
Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions wp-includes/ms-functions.php
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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', '' );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1269,7 +1268,7 @@ function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta
* @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;
Expand Down Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions wp-includes/ms-load.php
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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' ) {
Expand Down
8 changes: 4 additions & 4 deletions wp-login.php
Expand Up @@ -30,8 +30,8 @@
* @param string $wp_error Optional. The error to pass. Default empty.
* @param WP_Error $wp_error Optional. WordPress Error Object
*/
function login_header($title = 'Log In', $message = '', $wp_error = '') {
global $error, $interim_login, $current_site, $action;
function login_header( $title = 'Log In', $message = '', $wp_error = '' ) {
global $error, $interim_login, $action;

// Don't index any of these forms
add_action( 'login_head', 'wp_no_robots' );
Expand Down Expand Up @@ -90,7 +90,7 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {

if ( is_multisite() ) {
$login_header_url = network_home_url();
$login_header_title = $current_site->site_name;
$login_header_title = get_current_site()->site_name;
} else {
$login_header_url = __( 'http://wordpress.org/' );
$login_header_title = __( 'Powered by WordPress' );
Expand Down Expand Up @@ -262,7 +262,7 @@ function wp_login_viewport_meta() {
* @return bool|WP_Error True: when finish. WP_Error on error
*/
function retrieve_password() {
global $wpdb, $current_site, $wp_hasher;
global $wpdb, $wp_hasher;

$errors = new WP_Error();

Expand Down

0 comments on commit 74f77b8

Please sign in to comment.