Index: src/wp-includes/ms-load.php
===================================================================
--- src/wp-includes/ms-load.php	(revision 28187)
+++ src/wp-includes/ms-load.php	(working copy)
@@ -436,3 +436,45 @@
 	_deprecated_function( __FUNCTION__, '3.9' );
 	return $current_site;
 }
+
+/**
+ * Determine if a network has been defined already.
+ *
+ * @since 4.0.0
+ *
+ * @return bool True if a network is defined with constants. False if it is not.
+ */
+function wp_network_is_defined() {
+	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
+		$result = true;
+	} else {
+		$result = false;
+	}
+
+	return apply_filters( 'network_is_defined', $result );
+}
+
+/**
+ * Build a network object with predefined data.
+ *
+ * @since 4.0.0
+ *
+ * @return object Basic network information.
+ */
+function wp_get_defined_network() {
+	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
+		$current_site = new stdClass;
+		$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
+		$current_site->domain = DOMAIN_CURRENT_SITE;
+		$current_site->path = PATH_CURRENT_SITE;
+		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
+			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
+		} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
+			$current_site->blog_id = BLOGID_CURRENT_SITE;
+		}
+	} else {
+		$current_site = false;
+	}
+
+	return apply_filters( 'get_defined_network', $current_site );
+}
\ No newline at end of file
Index: src/wp-includes/ms-settings.php
===================================================================
--- src/wp-includes/ms-settings.php	(revision 28187)
+++ src/wp-includes/ms-settings.php	(working copy)
@@ -10,16 +10,6 @@
  * @since 3.0.0
  */
 
-/** Include Multisite initialization functions */
-require( ABSPATH . WPINC . '/ms-load.php' );
-require( ABSPATH . WPINC . '/ms-default-constants.php' );
-
-if ( defined( 'SUNRISE' ) )
-	include_once( WP_CONTENT_DIR . '/sunrise.php' );
-
-/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
-ms_subdomain_constants();
-
 if ( !isset( $current_site ) || !isset( $current_blog ) ) {
 
 	// Given the domain and path, let's try to identify the network and site.
@@ -42,16 +32,8 @@
 	list( $path ) = explode( '?', $path );
 
 	// If the network is defined in wp-config.php, we can simply use that.
-	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
-		$current_site = new stdClass;
-		$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
-		$current_site->domain = DOMAIN_CURRENT_SITE;
-		$current_site->path = PATH_CURRENT_SITE;
-		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
-			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
-		} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
-			$current_site->blog_id = BLOGID_CURRENT_SITE;
-		}
+	if ( wp_network_is_defined() ) {
+		$current_site = wp_get_defined_network();
 
 		if ( $current_site->domain === $domain && $current_site->path === $path ) {
 			$current_blog = get_site_by_path( $domain, $path );
Index: src/wp-settings.php
===================================================================
--- src/wp-settings.php	(revision 28187)
+++ src/wp-settings.php	(working copy)
@@ -91,6 +91,17 @@
 // Initialize multisite if enabled.
 if ( is_multisite() ) {
 	require( ABSPATH . WPINC . '/ms-blogs.php' );
+	/** Include Multisite initialization functions */
+	require( ABSPATH . WPINC . '/ms-load.php' );
+	require( ABSPATH . WPINC . '/ms-default-constants.php' );
+
+	if ( defined( 'SUNRISE' ) ) {
+		include_once( WP_CONTENT_DIR . '/sunrise.php' );
+	}
+
+	/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
+	ms_subdomain_constants();
+
 	require( ABSPATH . WPINC . '/ms-settings.php' );
 } elseif ( ! defined( 'MULTISITE' ) ) {
 	define( 'MULTISITE', false );
Index: tests/phpunit/includes/bootstrap.php
===================================================================
--- tests/phpunit/includes/bootstrap.php	(revision 28187)
+++ tests/phpunit/includes/bootstrap.php	(working copy)
@@ -55,10 +55,6 @@
 	echo "Running as multisite..." . PHP_EOL;
 	define( 'MULTISITE', true );
 	define( 'SUBDOMAIN_INSTALL', false );
-	define( 'DOMAIN_CURRENT_SITE', WP_TESTS_DOMAIN );
-	define( 'PATH_CURRENT_SITE', '/' );
-	define( 'SITE_ID_CURRENT_SITE', 1 );
-	define( 'BLOG_ID_CURRENT_SITE', 1 );
 	$GLOBALS['base'] = '/';
 } else {
 	echo "Running as single site... To run multisite, use -c tests/phpunit/multisite.xml" . PHP_EOL;
Index: tests/phpunit/tests/ms.php
===================================================================
--- tests/phpunit/tests/ms.php	(revision 28187)
+++ tests/phpunit/tests/ms.php	(working copy)
@@ -455,7 +455,7 @@
 		$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogname', 'title' => 'Test Title' ) );
 		$this->assertInternalType( 'int', $blog_id );
 
-		$this->assertEquals( 'http://' . DOMAIN_CURRENT_SITE . PATH_CURRENT_SITE . 'test_blogname/', get_blogaddress_by_name('test_blogname') );
+		$this->assertEquals( 'http://' . $current_site->domain . $current_site->path . 'test_blogname/', get_blogaddress_by_name('test_blogname') );
 
 		$this->assertEquals( $blog_id, get_id_from_blogname('test_blogname') );
 	}
@@ -1338,6 +1338,152 @@
 			$GLOBALS['super_admins'] = $old_global;
 		}
 	}
+
+	/**
+	 * @ticket 27884
+	 */
+	function test_multisite_bootstrap() {
+		global $current_site, $current_blog;
+
+		$network_ids = array(
+			'wordpress.org/'         => array( 'domain' => 'wordpress.org', 'path' => '/' ),
+			'make.wordpress.org/'    => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),
+		);
+
+		foreach ( $network_ids as &$id ) {
+			$id = $this->factory->network->create( $id );
+		}
+		unset( $id );
+
+		$ids = array(
+			'wordpress.org/'              => array( 'domain' => 'wordpress.org',      'path' => '/',         'site_id' => $network_ids['wordpress.org/'] ),
+			'wordpress.org/foo/'          => array( 'domain' => 'wordpress.org',      'path' => '/foo/',     'site_id' => $network_ids['wordpress.org/'] ),
+			'wordpress.org/foo/bar/'      => array( 'domain' => 'wordpress.org',      'path' => '/foo/bar/', 'site_id' => $network_ids['wordpress.org/'] ),
+			'make.wordpress.org/'         => array( 'domain' => 'make.wordpress.org', 'path' => '/',         'site_id' => $network_ids['make.wordpress.org/'] ),
+			'make.wordpress.org/foo/'     => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/',     'site_id' => $network_ids['make.wordpress.org/'] ),
+		);
+
+		foreach ( $ids as &$id ) {
+			$id = $this->factory->blog->create( $id );
+		}
+		unset( $id );
+
+		add_filter( 'network_is_defined', '__return_true' );
+		$this->_setup_network_define_filter( 'wordpress.org', '/', 1, 1 );
+		$this->_setup_host_request( 'wordpress.org', '/' );
+		$this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/2014/04/23/hello-world/' );
+		$this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/sample-page/' );
+		$this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/?p=1' );
+		$this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/wp-admin/' );
+		$this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/foo/' );
+		$this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/FOO/' );
+		$this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/foo/2014/04/23/hello-world/' );
+		$this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/foo/sample-page/' );
+		$this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/foo/?p=1' );
+		$this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'wordpress.org', '/foo/wp-admin/' );
+		$this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		// @todo not currently passing.
+		//$this->_setup_host_request( 'wordpress.org', '/foo/bar/' );
+		//$this->assertEquals( $ids['wordpress.org/foo/bar/'], $current_blog->blog_id );
+		//$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );
+
+		remove_filter( 'network_is_defined', '__return_true' );
+		add_filter( 'network_is_defined', '__return_false' );
+		$this->_setup_host_request( 'make.wordpress.org', '/' );
+		$this->assertEquals( $ids['make.wordpress.org/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['make.wordpress.org/'], $current_blog->site_id );
+
+		$this->_setup_host_request( 'make.wordpress.org', '/foo/' );
+		$this->assertEquals( $ids['make.wordpress.org/foo/'], $current_blog->blog_id );
+		$this->assertEquals( $network_ids['make.wordpress.org/'], $current_blog->site_id );
+	}
+
+	/**
+	 * Reset various globals required for a 'clean' multisite boot.
+	 *
+	 * The $wpdb and $table_prefix globals are required for ms-settings.php to
+	 * load properly.
+	 *
+	 * @param string $domain HTTP_HOST of the bootstrap request.
+	 * @param string $path   REQUEST_URI of the boot strap request.
+	 */
+	function _setup_host_request( $domain, $path ) {
+		global $current_site, $current_blog, $wpdb, $table_prefix;
+
+		$current_site = $current_blog = null;
+		$_SERVER['HTTP_HOST'] = $domain;
+		$_SERVER['REQUEST_URI'] = $path;
+		include ABSPATH . '/wp-includes/ms-settings.php';
+	}
+
+	/**
+	 * Use the get_defined_network filter to work around multisite constants.
+	 *
+	 * @param string $domain     Network domain that would be in DOMAIN_CURRENT_SITE.
+	 * @param string $path       Network path that would be in PATH_CURRENT_SITE.
+	 * @param int    $network_id Network ID that would be in SITE_ID_CURRENT_SITE.
+	 * @param int    $site_id    Network's site ID that would be in BLOG_ID_CURRENT_SITE.
+	 */
+	function _setup_network_define_filter( $domain, $path, $network_id = 1, $site_id = 1 ) {
+		global $test_network_domain, $test_network_path, $test_network_id, $test_site_id;
+
+		$test_network_domain = $domain;
+		$test_network_path = $path;
+		$test_network_id = $network_id;
+		$test_site_id = $site_id;
+
+		add_filter( 'get_defined_network', array( $this, '_filter_defined_network' ) );
+	}
+
+	/**
+	 * Filter the current_site object as if it had been predefined per the globals
+	 * configured in _setup_network_define_filter().
+	 *
+	 * @return stdClass The current_site object.
+	 */
+	function _filter_defined_network() {
+		global $test_network_domain, $test_network_path, $test_network_id, $test_site_id;
+
+		$current_site = new stdClass();
+		$current_site->domain = $test_network_domain;
+		$current_site->path = $test_network_path;
+		$current_site->id = $test_network_id;
+		$current_site->blog_id = $test_site_id;
+
+		return $current_site;
+	}
 }
 
 endif;
