Index: wp-includes/class-wp-theme.php
===================================================================
--- wp-includes/class-wp-theme.php	(revision 21400)
+++ wp-includes/class-wp-theme.php	(working copy)
@@ -1109,18 +1109,24 @@
 
 		$current = $blog_id == get_current_blog_id();
 
-		if ( $current )
+		if ( $current ) {
 			$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
-		else
-			$allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowedthemes' );
+		} else {
+			switch_to_blog( $blog_id );
+			$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
+			restore_current_blog();
+		}
 
 		// This is all super old MU back compat joy.
 		// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
 		if ( false === $allowed_themes[ $blog_id ] ) {
-			if ( $current )
+			if ( $current ) {
 				$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
-			else
-				$allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowed_themes' );
+			} else {
+				switch_to_blog( $blog_id );
+				$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
+				restore_current_blog();
+			}
 
 			if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) {
 				$allowed_themes[ $blog_id ] = array();
@@ -1139,8 +1145,10 @@
 					update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
 					delete_option( 'allowed_themes' );
 				} else {
-					update_blog_option( $blog_id, 'allowedthemes', $allowed_themes[ $blog_id ] );
-					delete_blog_option( $blog_id, 'allowed_themes' );
+					switch_to_blog( $blog_id );
+					update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
+					delete_option( 'allowed_themes' );
+					restore_current_blog();
 				}
 			}
 		}
Index: wp-includes/ms-blogs.php
===================================================================
--- wp-includes/ms-blogs.php	(revision 21400)
+++ wp-includes/ms-blogs.php	(working copy)
@@ -222,9 +222,11 @@
 		return $details;
 	}
 
-	$details->blogname		= get_blog_option( $blog_id, 'blogname' );
-	$details->siteurl		= get_blog_option( $blog_id, 'siteurl' );
-	$details->post_count	= get_blog_option( $blog_id, 'post_count' );
+	switch_to_blog( $blog_id );
+	$details->blogname		= get_option( 'blogname' );
+	$details->siteurl		= get_option( 'siteurl' );
+	$details->post_count	= get_option( 'post_count' );
+	restore_current_blog();
 
 	$details = apply_filters( 'blog_details', $details );
 
@@ -298,8 +300,11 @@
 			do_action( "make_ham_blog", $blog_id );
 	}
 
-	if ( isset($details[ 'public' ]) )
-		update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
+	if ( isset($details[ 'public' ]) ) {
+		switch_to_blog( $blog_id );
+		update_option( 'blog_public', $details[ 'public' ] );
+		restore_current_blog();
+	}
 
 	refresh_blog_details($blog_id);
 
@@ -307,127 +312,6 @@
 }
 
 /**
- * Retrieve option value for a given blog id based on name of option.
- *
- * If the option does not exist or does not have a value, then the return value
- * will be false. This is useful to check whether you need to install an option
- * and is commonly used during installation of plugin options and to test
- * whether upgrading is required.
- *
- * If the option was serialized then it will be unserialized when it is returned.
- *
- * @since MU
- *
- * @param int $id A blog ID. Can be null to refer to the current blog.
- * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
- * @param mixed $default Optional. Default value to return if the option does not exist.
- * @return mixed Value set for the option.
- */
-function get_blog_option( $id, $option, $default = false ) {
-	$id = (int) $id;
-
-	if ( empty( $id ) )
-		$id = get_current_blog_id();
-
-	if ( get_current_blog_id() == $id )
-		return get_option( $option, $default );
-
-	switch_to_blog( $id );
-	$option = get_option( $option, $default );
-	restore_current_blog();
-
-	return $option;
-}
-
-/**
- * Add a new option for a given blog id.
- *
- * You do not need to serialize values. If the value needs to be serialized, then
- * it will be serialized before it is inserted into the database. Remember,
- * resources can not be serialized or added as an option.
- *
- * You can create options without values and then update the values later.
- * Existing options will not be updated and checks are performed to ensure that you
- * aren't adding a protected WordPress option. Care should be taken to not name
- * options the same as the ones which are protected.
- *
- * @since MU
- *
- * @param int $id A blog ID. Can be null to refer to the current blog.
- * @param string $option Name of option to add. Expected to not be SQL-escaped.
- * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
- * @return bool False if option was not added and true if option was added.
- */
-function add_blog_option( $id, $option, $value ) {
-	$id = (int) $id;
-
-	if ( empty( $id ) )
-		$id = get_current_blog_id();
-
-	if ( get_current_blog_id() == $id )
-		return add_option( $option, $value );
-
-	switch_to_blog( $id );
-	$return = add_option( $option, $value );
-	restore_current_blog();
-
-	return $return;
-}
-
-/**
- * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
- *
- * @since MU
- *
- * @param int $id A blog ID. Can be null to refer to the current blog.
- * @param string $option Name of option to remove. Expected to not be SQL-escaped.
- * @return bool True, if option is successfully deleted. False on failure.
- */
-function delete_blog_option( $id, $option ) {
-	$id = (int) $id;
-
-	if ( empty( $id ) )
-		$id = get_current_blog_id();
-
-	if ( get_current_blog_id() == $id )
-		return delete_option( $option );
-
-	switch_to_blog( $id );
-	$return = delete_option( $option );
-	restore_current_blog();
-
-	return $return;
-}
-
-/**
- * Update an option for a particular blog.
- *
- * @since MU
- *
- * @param int $id The blog id
- * @param string $option The option key
- * @param mixed $value The option value
- * @return bool True on success, false on failrue.
- */
-function update_blog_option( $id, $option, $value, $deprecated = null ) {
-	$id = (int) $id;
-
-	if ( null !== $deprecated  )
-		_deprecated_argument( __FUNCTION__, '3.1' );
-
-	if ( get_current_blog_id() == $id )
-		return update_option( $option, $value );
-
-	switch_to_blog( $id );
-	$return = update_option( $option, $value );
-	restore_current_blog();
-
-	refresh_blog_details( $id );
-
-	return $return;
-}
-
-/**
  * Switch the current blog.
  *
  * This function is useful if you need to pull posts, or other information,
Index: wp-includes/class-wp-xmlrpc-server.php
===================================================================
--- wp-includes/class-wp-xmlrpc-server.php	(revision 21400)
+++ wp-includes/class-wp-xmlrpc-server.php	(working copy)
@@ -475,13 +475,15 @@
 			$blog_id = $blog->userblog_id;
 			$is_admin = current_user_can_for_blog( $blog_id, 'manage_options' );
 
+			switch_to_blog( $blog_id );
 			$struct[] = array(
 				'isAdmin'		=> $is_admin,
-				'url'			=> get_home_url( $blog_id, '/' ),
+				'url'			=> home_url( '/' ),
 				'blogid'		=> (string) $blog_id,
-				'blogName'		=> get_blog_option( $blog_id, 'blogname' ),
-				'xmlrpc'		=> get_site_url( $blog_id, 'xmlrpc.php' )
+				'blogName'		=> get_option( 'blogname' ),
+				'xmlrpc'		=> site_url( 'xmlrpc.php' )
 			);
+			restore_current_blog();
 		}
 
 		return $struct;
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 21400)
+++ wp-includes/link-template.php	(working copy)
@@ -1896,10 +1896,13 @@
 	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
 		$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
 
-	if ( empty( $blog_id ) || !is_multisite() )
+	if ( empty( $blog_id ) || !is_multisite() ) {
 		$url = get_option( 'home' );
-	else
-		$url = get_blog_option( $blog_id, 'home' );
+	} else {
+		switch_to_blog( $blog_id );
+		$url = get_option( 'home' );
+		restore_current_blog();
+	}
 
 	if ( 'relative' == $scheme )
 		$url = preg_replace( '#^.+://[^/]*#', '', $url );
@@ -1961,10 +1964,13 @@
 			$scheme = ( is_ssl() ? 'https' : 'http' );
 	}
 
-	if ( empty( $blog_id ) || !is_multisite() )
+	if ( empty( $blog_id ) || !is_multisite() ) {
 		$url = get_option( 'siteurl' );
-	else
-		$url = get_blog_option( $blog_id, 'siteurl' );
+	} else {
+		switch_to_blog( $blog_id );
+		$url = get_option( 'siteurl' );
+		restore_current_blog();
+	}
 
 	if ( 'relative' == $scheme )
 		$url = preg_replace( '#^.+://[^/]*#', '', $url );
Index: wp-includes/ms-deprecated.php
===================================================================
--- wp-includes/ms-deprecated.php	(revision 21400)
+++ wp-includes/ms-deprecated.php	(working copy)
@@ -270,3 +270,136 @@
 	}
 	return $url;
 }
+
+/**
+ * Retrieve option value for a given blog id based on name of option.
+ *
+ * If the option does not exist or does not have a value, then the return value
+ * will be false. This is useful to check whether you need to install an option
+ * and is commonly used during installation of plugin options and to test
+ * whether upgrading is required.
+ *
+ * If the option was serialized then it will be unserialized when it is returned.
+ *
+ * @since MU
+ * @deprecated 3.5.0
+ *
+ * @param int $id A blog ID. Can be null to refer to the current blog.
+ * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
+ * @param mixed $default Optional. Default value to return if the option does not exist.
+ * @return mixed Value set for the option.
+ */
+function get_blog_option( $id, $option, $default = false ) {
+	_deprecated_function( __FUNCTION__, '3.5' );
+
+	$id = (int) $id;
+
+	if ( empty( $id ) )
+		$id = get_current_blog_id();
+
+	if ( get_current_blog_id() == $id )
+		return get_option( $option, $default );
+
+	switch_to_blog( $id );
+	$option = get_option( $option, $default );
+	restore_current_blog();
+
+	return $option;
+}
+
+/**
+ * Add a new option for a given blog id.
+ *
+ * You do not need to serialize values. If the value needs to be serialized, then
+ * it will be serialized before it is inserted into the database. Remember,
+ * resources can not be serialized or added as an option.
+ *
+ * You can create options without values and then update the values later.
+ * Existing options will not be updated and checks are performed to ensure that you
+ * aren't adding a protected WordPress option. Care should be taken to not name
+ * options the same as the ones which are protected.
+ *
+ * @since MU
+ * @deprecated 3.5.0
+ *
+ * @param int $id A blog ID. Can be null to refer to the current blog.
+ * @param string $option Name of option to add. Expected to not be SQL-escaped.
+ * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
+ * @return bool False if option was not added and true if option was added.
+ */
+function add_blog_option( $id, $option, $value ) {
+	_deprecated_function( __FUNCTION__, '3.5' );
+
+	$id = (int) $id;
+
+	if ( empty( $id ) )
+		$id = get_current_blog_id();
+
+	if ( get_current_blog_id() == $id )
+		return add_option( $option, $value );
+
+	switch_to_blog( $id );
+	$return = add_option( $option, $value );
+	restore_current_blog();
+
+	return $return;
+}
+
+/**
+ * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
+ *
+ * @since MU
+ * @deprecated 3.5.0
+ *
+ * @param int $id A blog ID. Can be null to refer to the current blog.
+ * @param string $option Name of option to remove. Expected to not be SQL-escaped.
+ * @return bool True, if option is successfully deleted. False on failure.
+ */
+function delete_blog_option( $id, $option ) {
+	_deprecated_function( __FUNCTION__, '3.5' );
+
+	$id = (int) $id;
+
+	if ( empty( $id ) )
+		$id = get_current_blog_id();
+
+	if ( get_current_blog_id() == $id )
+		return delete_option( $option );
+
+	switch_to_blog( $id );
+	$return = delete_option( $option );
+	restore_current_blog();
+
+	return $return;
+}
+
+/**
+ * Update an option for a particular blog.
+ *
+ * @since MU
+ * @deprecated 3.5.0
+ *
+ * @param int $id The blog id
+ * @param string $option The option key
+ * @param mixed $value The option value
+ * @return bool True on success, false on failrue.
+ */
+function update_blog_option( $id, $option, $value, $deprecated = null ) {
+	_deprecated_function( __FUNCTION__, '3.5' );
+
+	$id = (int) $id;
+
+	if ( null !== $deprecated  )
+		_deprecated_argument( __FUNCTION__, '3.1' );
+
+	if ( get_current_blog_id() == $id )
+		return update_option( $option, $value );
+
+	switch_to_blog( $id );
+	$return = update_option( $option, $value );
+	restore_current_blog();
+
+	refresh_blog_details( $id );
+
+	return $return;
+}
Index: wp-admin/includes/class-wp-ms-sites-list-table.php
===================================================================
--- wp-admin/includes/class-wp-ms-sites-list-table.php	(revision 21400)
+++ wp-admin/includes/class-wp-ms-sites-list-table.php	(working copy)
@@ -230,8 +230,11 @@
 						echo "<td class='column-$column_name $column_name'$style>"; ?>
 							<a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
 							<?php
-							if ( 'list' != $mode )
-								echo '<p>' . sprintf( _x( '%1$s &#8211; <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_blog_option( $blog['blog_id'], 'blogname' ), get_blog_option( $blog['blog_id'], 'blogdescription ' ) ) . '</p>';
+							if ( 'list' != $mode ) {
+								switch_to_blog( $blog['blog_id'] );
+								echo '<p>' . sprintf( _x( '%1$s &#8211; <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>';
+								restore_current_blog();
+							}
 
 							// Preordered.
 							$actions = array(
Index: wp-admin/includes/ms.php
===================================================================
--- wp-admin/includes/ms.php	(revision 21400)
+++ wp-admin/includes/ms.php	(working copy)
@@ -411,7 +411,10 @@
 
 // Edit blog upload space setting on Edit Blog page
 function upload_space_setting( $id ) {
-	$quota = get_blog_option( $id, 'blog_upload_space' );
+	switch_to_blog( $id );
+	$quota = get_option( 'blog_upload_space' );
+	restore_current_blog();
+
 	if ( !$quota )
 		$quota = '';
 
Index: wp-admin/network/site-info.php
===================================================================
--- wp-admin/network/site-info.php	(revision 21400)
+++ wp-admin/network/site-info.php	(working copy)
@@ -135,10 +135,15 @@
 			<th scope="row"><?php _e( 'Path' ) ?></th>
 			<?php if ( $is_main_site ) { ?>
 			<td><code><?php echo esc_attr( $details->path ) ?></code></td>
-			<?php } else { ?>
+			<?php
+			} else {
+				switch_to_blog( $id );
+			?>
 			<td><input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" size="40" style='margin-bottom:5px;' />
-			<br /><input type="checkbox" style="width:20px;" name="update_home_url" value="update" <?php if ( get_blog_option( $id, 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_blog_option( $id, 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></td>
-			<?php } ?>
+			<br /><input type="checkbox" style="width:20px;" name="update_home_url" value="update" <?php if ( get_option( 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_option( 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></td>
+			<?php
+				restore_current_blog();
+			} ?>
 		</tr>
 		<tr class="form-field">
 			<th scope="row"><?php _ex( 'Registered', 'site' ) ?></th>
Index: wp-admin/network/site-users.php
===================================================================
--- wp-admin/network/site-users.php	(revision 21400)
+++ wp-admin/network/site-users.php	(working copy)
@@ -45,33 +45,26 @@
 	wp_die( __('Invalid site ID.') );
 
 $details = get_blog_details( $id );
-if ( !can_edit_network( $details->site_id ) )
+if ( ! can_edit_network( $details->site_id ) )
 	wp_die( __( 'You do not have permission to access this page.' ) );
 
 $is_main_site = is_main_site( $id );
 
-// get blog prefix
-$blog_prefix = $wpdb->get_blog_prefix( $id );
+switch_to_blog( $id );
 
-// @todo This is a hack. Eventually, add API to WP_Roles allowing retrieval of roles for a particular blog.
-if ( ! empty($wp_roles->use_db) ) {
-	$editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" );
-} else {
-	// Roles are stored in memory, not the DB.
-	$editblog_roles = $wp_roles->roles;
-}
-$default_role = get_blog_option( $id, 'default_role' );
+$editblog_roles = $wp_roles->roles;
 
+$default_role = get_option( 'default_role' );
+
 $action = $wp_list_table->current_action();
 
 if ( $action ) {
-	switch_to_blog( $id );
 
 	switch ( $action ) {
 		case 'newuser':
 			check_admin_referer( 'add-user', '_wpnonce_add-new-user' );
 			$user = $_POST['user'];
-			if ( !is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) {
+			if ( ! is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) {
 				$update = 'err_new';
 			} else {
 				$password = wp_generate_password( 12, false);
@@ -94,6 +87,7 @@
 				$newuser = $_POST['newuser'];
 				$userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
 				if ( $userid ) {
+					$blog_prefix = $wpdb->get_blog_prefix( $id );
 					$user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
 					if ( $user == false )
 						add_user_to_blog( $id, $userid, $_POST['new_role'] );
@@ -108,7 +102,7 @@
 			break;
 
 		case 'remove':
-			if ( !current_user_can('remove_users')  )
+			if ( ! current_user_can( 'remove_users' )  )
 				die(__('You can&#8217;t remove users.'));
 			check_admin_referer( 'bulk-users' );
 
@@ -152,11 +146,12 @@
 			break;
 	}
 
-	restore_current_blog();
 	wp_safe_redirect( add_query_arg( 'update', $update, $referer ) );
 	exit();
 }
 
+restore_current_blog();
+
 if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
 	wp_safe_redirect( $referer );
 	exit();
Index: wp-admin/network/upgrade.php
===================================================================
--- wp-admin/network/upgrade.php	(revision 21400)
+++ wp-admin/network/upgrade.php	(working copy)
@@ -60,9 +60,12 @@
 		}
 		echo "<ul>";
 		foreach ( (array) $blogs as $details ) {
-			$siteurl = get_blog_option( $details['blog_id'], 'siteurl' );
+			switch_to_blog( $details['blog_id'] );
+			$siteurl = site_url();
+			$upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
+			restore_current_blog();
 			echo "<li>$siteurl</li>";
-			$response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/upgrade.php?step=upgrade_db", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
+			$response = wp_remote_get( $upgrade_url, array( 'timeout' => 120, 'httpversion' => '1.1' ) );
 			if ( is_wp_error( $response ) )
 				wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>' ), $siteurl, $response->get_error_message() ) );
 			do_action( 'after_mu_upgrade', $response );
