Make WordPress Core

Ticket #30294: 30294.diff

File 30294.diff, 2.3 KB (added by jeremyfelt, 10 years ago)
  • src/wp-includes/functions.php

     
    38523852 * @return bool True if $network_id is the main network, or if not running Multisite.
    38533853 */
    38543854function is_main_network( $network_id = null ) {
    3855         global $wpdb;
    38563855
    3857         if ( ! is_multisite() )
     3856        // Always return true if not a multisite installation
     3857        if ( ! is_multisite() ) {
    38583858                return true;
     3859        }
    38593860
    38603861        $current_network_id = (int) get_current_site()->id;
    38613862
    3862         if ( ! $network_id )
     3863        if ( null === $network_id ) {
    38633864                $network_id = $current_network_id;
     3865        }
     3866
    38643867        $network_id = (int) $network_id;
    38653868
    3866         if ( defined( 'PRIMARY_NETWORK_ID' ) )
    3867                 return $network_id === (int) PRIMARY_NETWORK_ID;
     3869        return ( $network_id === get_main_network_id() );
     3870}
    38683871
    3869         if ( 1 === $current_network_id )
    3870                 return $network_id === $current_network_id;
     3872/**
     3873 * Get the main network ID.
     3874 *
     3875 * @since 4.3.0
     3876 *
     3877 * @return int 
     3878 */
     3879function get_main_network_id() {
     3880        global $wpdb;
    38713881
    3872         $primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' );
     3882        // Use constant if explicitly set.
     3883        if ( defined( 'MAIN_NETWORK_ID' ) ) {
     3884                $main_network_id = MAIN_NETWORK_ID;
    38733885
    3874         if ( $primary_network_id )
    3875                 return $network_id === $primary_network_id;
     3886        // If the current network has an ID of 1, assume it is the main network.
     3887        } elseif ( 1 === (int) get_current_site()->id ) {
     3888                $main_network_id = 1;
    38763889
    3877         $primary_network_id = (int) $wpdb->get_var( "SELECT id FROM $wpdb->site ORDER BY id LIMIT 1" );
    3878         wp_cache_add( 'primary_network_id', $primary_network_id, 'site-options' );
     3890        // Fallback on cached value, queried from sites table.
     3891        } else {
     3892                $main_network_id = wp_cache_get( 'main_network_id', 'site-options' );
    38793893
    3880         return $network_id === $primary_network_id;
     3894                if ( false === $main_network_id ) {
     3895                        $main_network_id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1" );
     3896                        wp_cache_add( 'main_network_id', $main_network_id, 'site-options' );
     3897                }
     3898        }
     3899
     3900        /**
     3901         * Filter the main network ID.
     3902         *
     3903         * @since 4.3.0
     3904         *
     3905         * @param int $main_network_id The ID of the main network.
     3906         */
     3907        return (int) apply_filters( 'get_main_network_id', $main_network_id );
    38813908}
    38823909
    38833910/**