WordPress.org

Make WordPress Core

Ticket #25030: 25030.7.diff

File 25030.7.diff, 2.7 KB (added by nacin, 8 years ago)
  • src/wp-includes/functions.php

     
    15541554        }
    15551555
    15561556        // If multisite (and if not the main site in a post-MU network)
    1557         if ( is_multisite() && ! ( is_main_site() && defined( 'MULTISITE' ) ) ) {
     1557        if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
    15581558
    15591559                if ( ! get_site_option( 'ms_files_rewriting' ) ) {
    15601560                        // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward:
     
    32463246}
    32473247
    32483248/**
    3249  * Is main site?
     3249 * Whether a site is the main site of the current network.
    32503250 *
    3251  *
    32523251 * @since 3.0.0
    3253  * @package WordPress
    32543252 *
    3255  * @param int $blog_id optional blog id to test (default current blog)
    3256  * @return bool True if not multisite or $blog_id is main site
     3253 * @param int $site_id Optional. Site ID to test. Defaults to current site.
     3254 * @return bool True if $site_id is the main site of the network, or if not running multisite.
    32573255 */
    3258 function is_main_site( $blog_id = '' ) {
     3256function is_main_site( $site_id = null ) {
     3257        // This is the current network's information; 'site' is old terminology.
    32593258        global $current_site;
    32603259
    32613260        if ( ! is_multisite() )
    32623261                return true;
    32633262
    3264         if ( ! $blog_id )
    3265                 $blog_id = get_current_blog_id();
     3263        if ( ! $site_id )
     3264                $site_id = get_current_blog_id();
    32663265
    3267         return $blog_id == $current_site->blog_id;
     3266        return (int) $site_id === (int) $current_site->blog_id;
    32683267}
    32693268
    32703269/**
     3270 * Whether a network is the main network of the multisite install.
     3271 *
     3272 * @since 3.7.0
     3273 *
     3274 * @param string $network_id Optional. Network ID to test. Defaults to current network.
     3275 * @return bool True if $network_id is the main network, or if not running multisite.
     3276 */
     3277function is_main_network( $network_id = null ) {
     3278        global $current_site, $wpdb;
     3279
     3280        $current_network_id = (int) $current_site->id;
     3281
     3282        if ( ! is_multisite() )
     3283                return true;
     3284
     3285        if ( ! $network_id )
     3286                $network_id = $current_network_id;
     3287        $network_id = (int) $network_id;
     3288
     3289        if ( defined( 'PRIMARY_NETWORK_ID' ) )
     3290                return $network_id === (int) PRIMARY_NETWORK_ID;
     3291
     3292        if ( 1 === $current_network_id )
     3293                return $network_id === $current_network_id;
     3294
     3295        $primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' );
     3296
     3297        if ( $primary_network_id )
     3298                return $network_id === $primary_network_id;
     3299
     3300        $primary_network_id = (int) $wpdb->get_var( "SELECT id FROM $wpdb->site ORDER BY id LIMIT 1" );
     3301        wp_cache_add( 'primary_network_id', $primary_network_id, 'site-options' );
     3302
     3303        return $network_id === $primary_network_id;
     3304}
     3305
     3306/**
    32713307 * Whether global terms are enabled.
    32723308 *
    32733309 *