Index: src/wp-admin/includes/class-wp-themes-list-table.php
===================================================================
--- src/wp-admin/includes/class-wp-themes-list-table.php	(revision 38454)
+++ src/wp-admin/includes/class-wp-themes-list-table.php	(working copy)
@@ -91,13 +91,14 @@
 			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 <a href="%1$s">enable</a> or <a href="%2$s">install</a> 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 <a href="%1$s">enable</a> or <a href="%2$s">install</a> 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 <a href="%1$s">enable</a> 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 <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ) );
 
 				return;
 			}
Index: src/wp-includes/cache.php
===================================================================
--- src/wp-includes/cache.php	(revision 38454)
+++ src/wp-includes/cache.php	(working copy)
@@ -729,14 +729,10 @@
 	 * 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() . ':' : '';
 
 
 		/**
Index: src/wp-includes/class-wp-user-query.php
===================================================================
--- src/wp-includes/class-wp-user-query.php	(revision 38454)
+++ src/wp-includes/class-wp-user-query.php	(working copy)
@@ -104,7 +104,7 @@
 	 */
 	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(),
Index: src/wp-includes/deprecated.php
===================================================================
--- src/wp-includes/deprecated.php	(revision 38454)
+++ src/wp-includes/deprecated.php	(working copy)
@@ -2357,7 +2357,6 @@
  * @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 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;
Index: src/wp-includes/load.php
===================================================================
--- src/wp-includes/load.php	(revision 38454)
+++ src/wp-includes/load.php	(working copy)
@@ -470,18 +470,15 @@
  *
  * @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,8 +492,9 @@
 		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
@@ -503,10 +501,11 @@
 	 * 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' ) );
Index: src/wp-includes/ms-blogs.php
===================================================================
--- src/wp-includes/ms-blogs.php	(revision 38454)
+++ src/wp-includes/ms-blogs.php	(working copy)
@@ -766,10 +766,12 @@
 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,
@@ -776,7 +778,7 @@
 	 * 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 @@
 
 	$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 @@
 	} 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 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 @@
 	}
 
 	$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 @@
 	} 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();
 
Index: src/wp-includes/ms-functions.php
===================================================================
--- src/wp-includes/ms-functions.php	(revision 38454)
+++ src/wp-includes/ms-functions.php	(working copy)
@@ -1966,15 +1966,12 @@
  *
  * @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.
Index: src/wp-includes/user.php
===================================================================
--- src/wp-includes/user.php	(revision 38454)
+++ src/wp-includes/user.php	(working copy)
@@ -965,8 +965,6 @@
  * @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 @@
 		'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
 	);
 
