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.


git-svn-id: https://develop.svn.wordpress.org/trunk@41348 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz 2017-09-08 16:32:39 +00:00
parent 7f3deb9988
commit 4705b3f27e

View File

@ -905,8 +905,16 @@ function populate_network( $network_id = 1, $domain = '', $email = '', $site_nam
$errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );
// Check for network collision.
if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) )
$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
$network_exists = false;
if ( is_multisite() ) {
if ( get_network( (int) $network_id ) ) {
$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
}
} else {
if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) {
$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
}
}
if ( ! is_email( $email ) )
$errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) );