Make WordPress Core


Ignore:
Timestamp:
10/14/2017 10:41:15 PM (7 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/src/wp-includes/functions.php

    r41753 r41861  
    44324432    }
    44334433
    4434     /**
    4435      * Filters the main site ID.
    4436      *
    4437      * Returning anything other than null will effectively short-circuit the function, returning
    4438      * the result parsed as an integer immediately.
    4439      *
    4440      * @since 4.9.0
    4441      *
    4442      * @param int|null $main_site_id If anything other than null is returned, it is interpreted as the main site ID.
    4443      * @param int $network_id The ID of the network for which the main site was detected.
    4444      */
    4445     $main_site_id = apply_filters( 'pre_get_main_site_id', null, $network->id );
    4446     if ( null !== $main_site_id ) {
    4447         return (int) $main_site_id;
    4448     }
    4449 
    4450     if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $network->domain === DOMAIN_CURRENT_SITE && $network->path === PATH_CURRENT_SITE )
    4451          || ( defined( 'SITE_ID_CURRENT_SITE' ) && $network->id == SITE_ID_CURRENT_SITE ) ) {
    4452         if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
    4453             return BLOG_ID_CURRENT_SITE;
    4454         } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
    4455             return BLOGID_CURRENT_SITE;
    4456         }
    4457     }
    4458 
    4459     $site = get_site();
    4460     if ( $site->domain === $network->domain && $site->path === $network->path ) {
    4461         $main_site_id = (int) $site->id;
    4462     } else {
    4463         $main_site_id = wp_cache_get( 'network:' . $network->id . ':main_site', 'site-options' );
    4464         if ( false === $main_site_id ) {
    4465             $_sites = get_sites( array(
    4466                 'fields'     => 'ids',
    4467                 'number'     => 1,
    4468                 'domain'     => $network->domain,
    4469                 'path'       => $network->path,
    4470                 'network_id' => $network->id,
    4471             ) );
    4472             $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0;
    4473 
    4474             wp_cache_add( 'network:' . $network->id . ':main_site', $main_site_id, 'site-options' );
    4475         }
    4476     }
    4477 
    4478     return (int) $main_site_id;
     4434    return $network->site_id;
    44794435}
    44804436
Note: See TracChangeset for help on using the changeset viewer.