Multisite: Wrap the main bootstrap process in a function

Introduce `ms_load_current_site_and_network`. This is used by core during the multisite bootstrap process to populate the `$current_site` and `$current_blog` globals based on a requested domain and path.

Return values from this function inform `ms-settings.php` as to whether a page view should continue, `ms_not_installed()` should fire, or a redirect to a new location should occur.

This was previously a procedural block in `ms-settings.php`. Wrapping this code and providing specific return values allows us to write tests that do not rely on the manual and repeated inclusion of `ms-settings.php`.

This should not be used by plugins or themes. Please.

See #34941.


git-svn-id: https://develop.svn.wordpress.org/trunk@37475 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2016-05-20 20:56:54 +00:00
parent 91f18f3d45
commit 757c0767f7
3 changed files with 199 additions and 172 deletions

View File

@@ -158,12 +158,12 @@ class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
'site_id' => self::$site_ids[ $site_key ],
);
$this->_setup_host_request( $domain, $path );
ms_load_current_site_and_network( $domain, $path );
$actual = array(
'network_id' => $current_blog->site_id,
'site_id' => $current_blog->blog_id,
);
$this->_setup_host_request( WP_TESTS_DOMAIN, '/' );
ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
$this->assertEqualSetsWithIndex( $expected, $actual );
}
@@ -197,13 +197,13 @@ class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
'site_id' => self::$site_ids['wordpress.org/foo/bar/'],
);
add_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
$this->_setup_host_request( 'wordpress.org', '/foo/bar/' );
ms_load_current_site_and_network( 'wordpress.org', '/foo/bar/' );
$actual = array(
'network_id' => $current_blog->site_id,
'site_id' => $current_blog->blog_id,
);
remove_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
$this->_setup_host_request( WP_TESTS_DOMAIN, '/' );
ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
$this->assertEqualSetsWithIndex( $expected, $actual );
}
@@ -211,26 +211,6 @@ class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
public function filter_path_segments_to_two() {
return 2;
}
/**
* 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, $table_prefix, $wpdb;
$table_prefix = WP_TESTS_TABLE_PREFIX;
$current_site = $current_blog = null;
$_SERVER['HTTP_HOST'] = $domain;
$_SERVER['REQUEST_URI'] = $path;
include ABSPATH . '/wp-includes/ms-settings.php';
}
}
endif;