WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/14/2017 10:41:15 PM (3 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/getMainSiteId.php

    r41380 r41861  
    106106        return 333;
    107107    }
     108
     109    /**
     110     * @ticket 41936
     111     */
     112    public function test_get_main_site_id_with_property_value() {
     113        global $current_site;
     114
     115        $original_main_site_id = $current_site->blog_id;
     116        $current_site->blog_id = '123';
     117
     118        $result = get_main_site_id();
     119
     120        $current_site->blog_id = $original_main_site_id;
     121
     122        $this->assertSame( 123, $result );
     123    }
     124
     125    /**
     126     * @ticket 41936
     127     */
     128    public function test_get_main_site_id_filtered_with_property_value() {
     129        global $current_site;
     130
     131        $original_main_site_id = $current_site->blog_id;
     132        $current_site->blog_id = '123';
     133
     134        add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );
     135        $result = get_main_site_id();
     136
     137        $current_site->blog_id = $original_main_site_id;
     138
     139        $this->assertSame( 333, $result );
     140    }
    108141}
    109142
Note: See TracChangeset for help on using the changeset viewer.