From 6ced1764599eaa661eb031dadf189f294d679951 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 8 Sep 2017 16:33:43 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@41348 git-svn-id: http://core.svn.wordpress.org/trunk@41181 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 12 ++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index d5ba04c95b..c9cee07527 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -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.' ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 1c3a37d22d..a03881e4a3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41347'; +$wp_version = '4.9-alpha-41348'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.