WordPress.org

Make WordPress Core

Changeset 41718


Ignore:
Timestamp:
10/03/2017 07:26:01 PM (2 years ago)
Author:
flixos90
Message:

Multisite: Use WP_Network_Query in ms_load_current_site_and_network().

This gets rid of the last readonly direct database query for networks in core. 🎉

Props spacedmonkey.
Fixes #41762.

File:
1 edited

Legend:

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

    r41380 r41718  
    269269 * @access private
    270270 *
    271  * @global wpdb       $wpdb         WordPress database abstraction object.
    272271 * @global WP_Network $current_site The current network.
    273272 * @global WP_Site    $current_blog The current site.
     
    282281 */
    283282function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
    284     global $wpdb, $current_site, $current_blog;
     283    global $current_site, $current_blog;
    285284
    286285    // If the network is defined in wp-config.php, we can simply use that.
     
    315314        if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
    316315            // Are there even two networks installed?
    317             $one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic]
    318             if ( 1 === $wpdb->num_rows ) {
    319                 $current_site = new WP_Network( $one_network );
     316            $networks = get_networks( array( 'number' => 2 ) );
     317            if ( count( $networks ) === 1 ) {
     318                $current_site = array_shift( $networks );
    320319                wp_cache_add( 'current_network', $current_site, 'site-options' );
    321             } elseif ( 0 === $wpdb->num_rows ) {
     320            } elseif ( empty( $networks ) ) {
    322321                // A network not found hook should fire here.
    323322                return false;
Note: See TracChangeset for help on using the changeset viewer.