Multisite: Take WP_Network::$blog_id into account in get_main_site_id().

When the `WP_Network::$blog_id` property is set manually, for example in the multisite bootstrap process, `get_main_site_id()` should use that value instead of running its own logic. The main logic for the function was therefore moved into the internal `WP_Network::get_main_site_id()` method, which is now being accessed by the function through the magic property handling for `WP_Network::$blog_id` (and its equivalent `WP_Network::$site_id`).

Props spacedmonkey, jeremyfelt.
Fixes #41936.


git-svn-id: https://develop.svn.wordpress.org/trunk@41861 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz
2017-10-14 22:41:15 +00:00
parent a626ef6c81
commit 4d6c257cf9
3 changed files with 93 additions and 52 deletions
@@ -105,6 +105,39 @@ class Tests_Multisite_Get_Main_Site_ID extends WP_UnitTestCase {
public function filter_get_main_site_id() {
return 333;
}
/**
* @ticket 41936
*/
public function test_get_main_site_id_with_property_value() {
global $current_site;
$original_main_site_id = $current_site->blog_id;
$current_site->blog_id = '123';
$result = get_main_site_id();
$current_site->blog_id = $original_main_site_id;
$this->assertSame( 123, $result );
}
/**
* @ticket 41936
*/
public function test_get_main_site_id_filtered_with_property_value() {
global $current_site;
$original_main_site_id = $current_site->blog_id;
$current_site->blog_id = '123';
add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );
$result = get_main_site_id();
$current_site->blog_id = $original_main_site_id;
$this->assertSame( 333, $result );
}
}
endif;