WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/19/2016 04:46:14 AM (3 years ago)
Author:
jeremyfelt
Message:

Multisite: Use get_network() and get_current_network_id() for current network data.

get_network() falls back to the current network when called without any arguments. Between this and get_current_network_id(), we can replace almost all instances of the global $current_site and all instances of get_current_site().

This effectively deprecates get_current_site(), something that we'll do in a future ticket.

Props flixos90.
Fixes #37414.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r38810 r38814  
    43034303 * @since 3.0.0
    43044304 *
    4305  * @global object $current_site
    4306  *
    43074305 * @param int $site_id Optional. Site ID to test. Defaults to current site.
    43084306 * @return bool True if $site_id is the main site of the network, or if not
     
    43104308 */
    43114309function is_main_site( $site_id = null ) {
    4312     // This is the current network's information; 'site' is old terminology.
    4313     global $current_site;
    4314 
    43154310    if ( ! is_multisite() )
    43164311        return true;
     
    43194314        $site_id = get_current_blog_id();
    43204315
    4321     return (int) $site_id === (int) $current_site->blog_id;
     4316    return (int) $site_id === (int) get_network()->site_id;
    43224317}
    43234318
     
    43354330    }
    43364331
    4337     $current_network_id = (int) get_current_site()->id;
    4338 
    43394332    if ( null === $network_id ) {
    4340         $network_id = $current_network_id;
     4333        $network_id = get_current_network_id();
    43414334    }
    43424335
     
    43584351    }
    43594352
    4360     $current_site = get_current_site();
     4353    $current_network = get_network();
    43614354
    43624355    if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
    43634356        $main_network_id = PRIMARY_NETWORK_ID;
    4364     } elseif ( isset( $current_site->id ) && 1 === (int) $current_site->id ) {
     4357    } elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) {
    43654358        // If the current network has an ID of 1, assume it is the main network.
    43664359        $main_network_id = 1;
Note: See TracChangeset for help on using the changeset viewer.