Index: src/wp-includes/ms-functions.php
===================================================================
--- src/wp-includes/ms-functions.php	(revision 38853)
+++ src/wp-includes/ms-functions.php	(working copy)
@@ -53,9 +53,9 @@
 	if ( false !== $primary_blog ) {
 		if ( ! isset( $blogs[ $primary_blog ] ) ) {
 			update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
-			$primary = get_blog_details( $first_blog->userblog_id );
+			$primary = get_site( $first_blog->userblog_id );
 		} else {
-			$primary = get_blog_details( $primary_blog );
+			$primary = get_site( $primary_blog );
 		}
 	} else {
 		//TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog?
@@ -71,7 +71,7 @@
 			foreach ( (array) $blogs as $blog_id => $blog ) {
 				if ( $blog->site_id != $wpdb->siteid )
 					continue;
-				$details = get_blog_details( $blog_id );
+				$details = get_site( $blog_id );
 				if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
 					$ret = $blog;
 					if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )
Index: tests/phpunit/tests/user/multisite.php
===================================================================
--- tests/phpunit/tests/user/multisite.php	(revision 38853)
+++ tests/phpunit/tests/user/multisite.php	(working copy)
@@ -365,6 +365,72 @@
 		$this->assertFalse( wpmu_delete_user( $u_obj ) );
 		$this->assertEquals( $u_obj->ID, username_exists( $u_obj->user_login ) );
 	}
+
+	/**
+	 * @ticket 38355
+	 */
+	public function test_get_active_blog_for_user_with_no_sites() {
+		$current_site_id = get_current_blog_id();
+		$user_id = self::factory()->user->create();
+		remove_user_from_blog( $user_id, $current_site_id );
+
+		$result = get_active_blog_for_user( $user_id );
+		$this->assertNull( $result );
+	}
+
+	/**
+	 * @ticket 38355
+	 */
+	public function test_get_active_blog_for_user_with_primary_site() {
+		$user_id = self::factory()->user->create();
+		self::factory()->blog->create( array( 'user_id' => $user_id ) );
+		self::factory()->blog->create( array( 'user_id' => $user_id ) );
+
+		$sites = get_blogs_of_user( $user_id );
+		$site_ids = array_keys( $sites );
+		$primary_site_id = $site_ids[1];
+
+		update_user_meta( $user_id, 'primary_blog', $primary_site_id );
+
+		$result = get_active_blog_for_user( $user_id );
+		$this->assertEquals( $primary_site_id, $result->id );
+	}
+
+	/**
+	 * @ticket 38355
+	 */
+	public function test_get_active_blog_for_user_without_primary_site() {
+		$user_id = self::factory()->user->create();
+		self::factory()->blog->create( array( 'user_id' => $user_id ) );
+
+		$sites = get_blogs_of_user( $user_id );
+		$site_ids = array_keys( $sites );
+		$primary_site_id = $site_ids[0];
+
+		delete_user_meta( $user_id, 'primary_blog' );
+
+		$result = get_active_blog_for_user( $user_id );
+		$this->assertEquals( $primary_site_id, $result->id );
+	}
+
+	/**
+	 * @ticket 38355
+	 */
+	public function test_get_active_blog_for_user_with_spam_site() {
+		$current_site_id = get_current_blog_id();
+		$user_id = self::factory()->user->create();
+
+		$site_id = self::factory()->blog->create( array(
+			'user_id' => $user_id,
+			'meta'    => array( 'spam' => 1 ),
+		) );
+
+		add_user_to_blog( $user_id, $site_id, 'subscriber' );
+		update_user_meta( $user_id, 'primary_blog', $site_id );
+
+		$result = get_active_blog_for_user( $user_id );
+		$this->assertEquals( $current_site_id, $result->id );
+	}
 }
 
 endif ;
