diff --git a/wp-admin/includes/class-wp-themes-list-table.php b/wp-admin/includes/class-wp-themes-list-table.php index a232cd05b2..9ac4597b37 100644 --- a/wp-admin/includes/class-wp-themes-list-table.php +++ b/wp-admin/includes/class-wp-themes-list-table.php @@ -91,13 +91,14 @@ class WP_Themes_List_Table extends WP_List_Table { return; } + $blog_id = get_current_blog_id(); if ( is_multisite() ) { if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { - printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to enable or install more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) ); + printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to enable or install more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ), network_admin_url( 'theme-install.php' ) ); return; } elseif ( current_user_can( 'manage_network_themes' ) ) { - printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to enable more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) ); + printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to enable more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ) ); return; } diff --git a/wp-includes/cache.php b/wp-includes/cache.php index 623895d412..b9457a7eee 100644 --- a/wp-includes/cache.php +++ b/wp-includes/cache.php @@ -729,14 +729,10 @@ class WP_Object_Cache { * Sets up object properties; PHP 5 style constructor. * * @since 2.0.8 - * - * @global int $blog_id Global blog ID. */ public function __construct() { - global $blog_id; - $this->multisite = is_multisite(); - $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; + $this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : ''; /** diff --git a/wp-includes/class-wp-user-query.php b/wp-includes/class-wp-user-query.php index a91aa1439b..9d3becb9b1 100644 --- a/wp-includes/class-wp-user-query.php +++ b/wp-includes/class-wp-user-query.php @@ -104,7 +104,7 @@ class WP_User_Query { */ public static function fill_query_vars( $args ) { $defaults = array( - 'blog_id' => $GLOBALS['blog_id'], + 'blog_id' => get_current_blog_id(), 'role' => '', 'role__in' => array(), 'role__not_in' => array(), diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index d3cea96548..48f0173cf7 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -2357,7 +2357,6 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) { * @see get_users() * * @global wpdb $wpdb WordPress database abstraction object. - * @global int $blog_id The site ID of the site for those that use more than one site. * * @param int $id Site ID. * @return array List of users that are part of that site ID @@ -2365,9 +2364,10 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) { function get_users_of_blog( $id = '' ) { _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' ); - global $wpdb, $blog_id; - if ( empty($id) ) - $id = (int) $blog_id; + global $wpdb; + if ( empty( $id ) ) { + $id = get_current_blog_id(); + } $blog_prefix = $wpdb->get_blog_prefix($id); $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ); return $users; diff --git a/wp-includes/load.php b/wp-includes/load.php index 14f58bc104..ef92a80924 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -470,18 +470,15 @@ function wp_using_ext_object_cache( $using = null ) { * * @since 3.0.0 * @access private - * - * @global int $blog_id Blog ID. */ function wp_start_object_cache() { - global $blog_id; - $first_init = false; if ( ! function_exists( 'wp_cache_init' ) ) { if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { require_once ( WP_CONTENT_DIR . '/object-cache.php' ); - if ( function_exists( 'wp_cache_init' ) ) + if ( function_exists( 'wp_cache_init' ) ) { wp_using_ext_object_cache( true ); + } } $first_init = true; @@ -495,18 +492,20 @@ function wp_start_object_cache() { wp_using_ext_object_cache( true ); } - if ( ! wp_using_ext_object_cache() ) + if ( ! wp_using_ext_object_cache() ) { require_once ( ABSPATH . WPINC . '/cache.php' ); + } /* * If cache supports reset, reset instead of init if already * initialized. Reset signals to the cache that global IDs * have changed and it may need to update keys and cleanup caches. */ - if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) - wp_cache_switch_to_blog( $blog_id ); - elseif ( function_exists( 'wp_cache_init' ) ) + if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { + wp_cache_switch_to_blog( get_current_blog_id() ); + } elseif ( function_exists( 'wp_cache_init' ) ) { wp_cache_init(); + } if ( function_exists( 'wp_cache_add_global_groups' ) ) { wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 2a1549f98c..a277402d56 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -766,17 +766,19 @@ function update_blog_option( $id, $option, $value, $deprecated = null ) { function switch_to_blog( $new_blog, $deprecated = null ) { global $wpdb; - if ( empty( $new_blog ) ) - $new_blog = $GLOBALS['blog_id']; + $blog_id = get_current_blog_id(); + if ( empty( $new_blog ) ) { + $new_blog = $blog_id; + } - $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; + $GLOBALS['_wp_switched_stack'][] = $blog_id; /* * If we're switching to the same blog id that we're on, * set the right vars, do the associated actions, but skip * the extra unnecessary work */ - if ( $new_blog == $GLOBALS['blog_id'] ) { + if ( $new_blog == $blog_id ) { /** * Fires when the blog is switched. * @@ -792,7 +794,7 @@ function switch_to_blog( $new_blog, $deprecated = null ) { $wpdb->set_blog_id( $new_blog ); $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); - $prev_blog_id = $GLOBALS['blog_id']; + $prev_blog_id = $blog_id; $GLOBALS['blog_id'] = $new_blog; if ( function_exists( 'wp_cache_switch_to_blog' ) ) { @@ -800,11 +802,11 @@ function switch_to_blog( $new_blog, $deprecated = null ) { } else { global $wp_object_cache; - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { $global_groups = $wp_object_cache->global_groups; - else + } else { $global_groups = false; - + } wp_cache_init(); if ( function_exists( 'wp_cache_add_global_groups' ) ) { @@ -848,12 +850,14 @@ function switch_to_blog( $new_blog, $deprecated = null ) { function restore_current_blog() { global $wpdb; - if ( empty( $GLOBALS['_wp_switched_stack'] ) ) + if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { return false; + } $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); + $blog_id = get_current_blog_id(); - if ( $GLOBALS['blog_id'] == $blog ) { + if ( $blog_id == $blog ) { /** This filter is documented in wp-includes/ms-blogs.php */ do_action( 'switch_blog', $blog, $blog ); // If we still have items in the switched stack, consider ourselves still 'switched' @@ -862,7 +866,7 @@ function restore_current_blog() { } $wpdb->set_blog_id( $blog ); - $prev_blog_id = $GLOBALS['blog_id']; + $prev_blog_id = $blog_id; $GLOBALS['blog_id'] = $blog; $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); @@ -871,10 +875,11 @@ function restore_current_blog() { } else { global $wp_object_cache; - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { $global_groups = $wp_object_cache->global_groups; - else + } else { $global_groups = false; + } wp_cache_init(); diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index d133324db0..0d97ea77df 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -1966,15 +1966,12 @@ function maybe_add_existing_user_to_blog() { * * @since MU * - * @global int $blog_id - * * @param array $details * @return true|WP_Error|void */ function add_existing_user_to_blog( $details = false ) { - global $blog_id; - if ( is_array( $details ) ) { + $blog_id = get_current_blog_id(); $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role' ] ); /** * Fires immediately after an existing user is added to a site. diff --git a/wp-includes/user.php b/wp-includes/user.php index f372810913..9ff6455f38 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -965,8 +965,6 @@ function setup_userdata($for_user_id = '') { * @since 2.3.0 * @since 4.5.0 Added the 'display_name_with_login' value for 'show'. * - * @global int $blog_id - * * @param array|string $args { * Optional. Array or string of arguments to generate a drop-down of users. * See WP_User_Query::prepare_query() for additional available arguments. @@ -1016,7 +1014,7 @@ function wp_dropdown_users( $args = '' ) { 'include' => '', 'exclude' => '', 'multi' => 0, 'show' => 'display_name', 'echo' => 1, 'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '', - 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false, + 'blog_id' => get_current_blog_id(), 'who' => '', 'include_selected' => false, 'option_none_value' => -1 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 8c2ddb0480..76f63f8ee4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38456'; +$wp_version = '4.7-alpha-38457'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.