Make WordPress Core


Ignore:
Timestamp:
09/15/2017 11:14:49 AM (8 years ago)
Author:
flixos90
Message:

Multisite: Introduce get_main_site_id().

This function can be used to easily get the main site ID of a given network via the optional $network_id parameter, which defaults to the current network. The existing is_main_site() now uses the new function internally and now accepts an optional $network_id parameter as well.

The main purpose of the new function at this point is to ensure that the WP_Network::$blog_id property is always set. Magic getters in the class have been adjusted to auto-fill the property when it is accessed and empty. Furthermore the function encapsulates logic that was previously part of ms_load_current_site_and_network() and has been replaced with a call to the function now.

Props spacedmonkey, jeremyfelt, johnjamesjacoby, flixos90.
Fixes #29684.

File:
1 edited

Legend:

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

    r41058 r41380  
    1212    protected $suppress = false;
    1313    protected static $network_ids;
     14    protected static $site_ids;
    1415
    1516    function setUp() {
     
    3435        }
    3536        unset( $id );
     37
     38        self::$site_ids = array(
     39            'make.wordpress.org/'     => array( 'domain' => 'make.wordpress.org', 'path' => '/',         'site_id' => self::$network_ids['make.wordpress.org/'] ),
     40            'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/',     'site_id' => self::$network_ids['make.wordpress.org/'] ),
     41        );
     42
     43        foreach ( self::$site_ids as &$id ) {
     44            $id = $factory->blog->create( $id );
     45        }
     46        unset( $id );
    3647    }
    3748
    3849    public static function wpTearDownAfterClass() {
    3950        global $wpdb;
     51
     52        foreach( self::$site_ids as $id ) {
     53            wpmu_delete_blog( $id, true );
     54        }
    4055
    4156        foreach( self::$network_ids as $id ) {
     
    10291044        return $original_value;
    10301045    }
     1046
     1047    /**
     1048     * @ticket 29684
     1049     */
     1050    public function test_is_main_site_different_network() {
     1051        $this->assertTrue( is_main_site( self::$site_ids['make.wordpress.org/'], self::$network_ids['make.wordpress.org/'] ) );
     1052    }
     1053
     1054    /**
     1055     * @ticket 29684
     1056     */
     1057    public function test_is_main_site_different_network_random_site() {
     1058        $this->assertFalse( is_main_site( self::$site_ids['make.wordpress.org/foo/'], self::$network_ids['make.wordpress.org/'] ) );
     1059    }
    10311060}
    10321061
Note: See TracChangeset for help on using the changeset viewer.