Make WordPress Core

Changeset 41348


Ignore:
Timestamp:
09/08/2017 04:32:39 PM (7 years ago)
Author:
flixos90
Message:

Multisite: Use get_network() in populate_network() to check whether a network with the given ID already exists.

When multisite is setup already, e.g. in a multi network environment, this change gives a performance benefit over the direct SQL query that was previously used. The SQL query remains in place for when setting up multisite initially as the network API is not available at that point.

Props spacedmonkey.
Fixes #41805.

File:
1 edited

Legend:

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

    r41289 r41348  
    906906
    907907    // Check for network collision.
    908     if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) )
    909         $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
     908    $network_exists = false;
     909    if ( is_multisite() ) {
     910        if ( get_network( (int) $network_id ) ) {
     911            $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
     912        }
     913    } else {
     914        if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) {
     915            $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
     916        }
     917    }
    910918
    911919    if ( ! is_email( $email ) )
Note: See TracChangeset for help on using the changeset viewer.