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. Built from https://develop.svn.wordpress.org/trunk@41718 git-svn-id: http://core.svn.wordpress.org/trunk@41552 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1130241bbd
commit
f821106df8
|
@ -268,7 +268,6 @@ function get_site_by_path( $domain, $path, $segments = null ) {
|
||||||
* @since 4.6.0
|
* @since 4.6.0
|
||||||
* @access private
|
* @access private
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
|
||||||
* @global WP_Network $current_site The current network.
|
* @global WP_Network $current_site The current network.
|
||||||
* @global WP_Site $current_blog The current site.
|
* @global WP_Site $current_blog The current site.
|
||||||
*
|
*
|
||||||
|
@ -281,7 +280,7 @@ function get_site_by_path( $domain, $path, $segments = null ) {
|
||||||
* Redirect URL if parts exist, but the request as a whole can not be fulfilled.
|
* Redirect URL if parts exist, but the request as a whole can not be fulfilled.
|
||||||
*/
|
*/
|
||||||
function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
|
function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
|
||||||
global $wpdb, $current_site, $current_blog;
|
global $current_site, $current_blog;
|
||||||
|
|
||||||
// If the network is defined in wp-config.php, we can simply use that.
|
// If the network is defined in wp-config.php, we can simply use that.
|
||||||
if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
|
if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
|
||||||
|
@ -314,11 +313,11 @@ function ms_load_current_site_and_network( $domain, $path, $subdomain = false )
|
||||||
*/
|
*/
|
||||||
if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
|
if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
|
||||||
// Are there even two networks installed?
|
// Are there even two networks installed?
|
||||||
$one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic]
|
$networks = get_networks( array( 'number' => 2 ) );
|
||||||
if ( 1 === $wpdb->num_rows ) {
|
if ( count( $networks ) === 1 ) {
|
||||||
$current_site = new WP_Network( $one_network );
|
$current_site = array_shift( $networks );
|
||||||
wp_cache_add( 'current_network', $current_site, 'site-options' );
|
wp_cache_add( 'current_network', $current_site, 'site-options' );
|
||||||
} elseif ( 0 === $wpdb->num_rows ) {
|
} elseif ( empty( $networks ) ) {
|
||||||
// A network not found hook should fire here.
|
// A network not found hook should fire here.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9-alpha-41717';
|
$wp_version = '4.9-alpha-41718';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue