WordPress.org

Make WordPress Core

Changeset 38632


Ignore:
Timestamp:
09/20/2016 06:46:52 PM (20 months ago)
Author:
jeremyfelt
Message:

Multisite: Use get_networks() in get_main_network_id().

The manual query for the main network ID can now be replaced with a cached get_networks() query. This allows us to eliminate the primary_network_id cache key entirely.

Props spacedmonkey.
Fixes #37218.

File:
1 edited

Legend:

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

    r38608 r38632  
    43544354 * @since 4.3.0
    43554355 *
    4356  * @global wpdb $wpdb WordPress database abstraction object.
    4357  *
    43584356 * @return int The ID of the main network.
    43594357 */
    43604358function get_main_network_id() {
    4361     global $wpdb;
    4362 
    43634359    if ( ! is_multisite() ) {
    43644360        return 1;
     
    43734369        $main_network_id = 1;
    43744370    } else {
    4375         $main_network_id = wp_cache_get( 'primary_network_id', 'site-options' );
    4376 
    4377         if ( false === $main_network_id ) {
    4378             $main_network_id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1" );
    4379             wp_cache_add( 'primary_network_id', $main_network_id, 'site-options' );
    4380         }
     4371        $_networks = get_networks( array( 'fields' => 'ids', 'number' => 1 ) );
     4372        $main_network_id = array_shift( $_networks );
    43814373    }
    43824374
Note: See TracChangeset for help on using the changeset viewer.