diff --git a/wp-includes/ms-settings.php b/wp-includes/ms-settings.php index 3e10ba56fc..892548f5de 100644 --- a/wp-includes/ms-settings.php +++ b/wp-includes/ms-settings.php @@ -172,10 +172,10 @@ if ( !isset( $current_site ) || !isset( $current_blog ) ) { if ( ! isset( $current_site->blog_id ) ) { if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) { $current_site->blog_id = $current_blog->blog_id; - } else { - // @todo we should be able to cache the blog ID of a network's main site easily. + } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) { $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) ); + wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' ); } }