Networks and Sites: Don't unnecessarily switch to the current blog in `get_blog_details()`.
Props arpitgshah, djennez, acsnaterse, joostdevalk, SergeyBiryukov. Fixes #50391. git-svn-id: https://develop.svn.wordpress.org/trunk@48044 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
eb06a59f53
commit
d9c53241dc
|
@ -238,12 +238,21 @@ function get_blog_details( $fields = null, $get_all = true ) {
|
||||||
return $details;
|
return $details;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_to_blog( $blog_id );
|
$switched_blog = false;
|
||||||
|
|
||||||
|
if ( get_current_blog_id() !== $blog_id ) {
|
||||||
|
switch_to_blog( $blog_id );
|
||||||
|
$switched_blog = true;
|
||||||
|
}
|
||||||
|
|
||||||
$details->blogname = get_option( 'blogname' );
|
$details->blogname = get_option( 'blogname' );
|
||||||
$details->siteurl = get_option( 'siteurl' );
|
$details->siteurl = get_option( 'siteurl' );
|
||||||
$details->post_count = get_option( 'post_count' );
|
$details->post_count = get_option( 'post_count' );
|
||||||
$details->home = get_option( 'home' );
|
$details->home = get_option( 'home' );
|
||||||
restore_current_blog();
|
|
||||||
|
if ( $switched_blog ) {
|
||||||
|
restore_current_blog();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters a blog's details.
|
* Filters a blog's details.
|
||||||
|
@ -516,7 +525,9 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) {
|
||||||
* or 'restore' when called from restore_current_blog().
|
* or 'restore' when called from restore_current_blog().
|
||||||
*/
|
*/
|
||||||
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
|
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
|
||||||
|
|
||||||
$GLOBALS['switched'] = true;
|
$GLOBALS['switched'] = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,6 +545,7 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) {
|
||||||
} else {
|
} else {
|
||||||
$global_groups = false;
|
$global_groups = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_cache_init();
|
wp_cache_init();
|
||||||
|
|
||||||
if ( function_exists( 'wp_cache_add_global_groups' ) ) {
|
if ( function_exists( 'wp_cache_add_global_groups' ) ) {
|
||||||
|
@ -542,12 +554,14 @@ function switch_to_blog( $new_blog_id, $deprecated = null ) {
|
||||||
} else {
|
} else {
|
||||||
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
|
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
|
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This filter is documented in wp-includes/ms-blogs.php */
|
/** This filter is documented in wp-includes/ms-blogs.php */
|
||||||
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
|
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
|
||||||
|
|
||||||
$GLOBALS['switched'] = true;
|
$GLOBALS['switched'] = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -581,8 +595,10 @@ function restore_current_blog() {
|
||||||
if ( $new_blog_id == $prev_blog_id ) {
|
if ( $new_blog_id == $prev_blog_id ) {
|
||||||
/** This filter is documented in wp-includes/ms-blogs.php */
|
/** This filter is documented in wp-includes/ms-blogs.php */
|
||||||
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
|
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
|
||||||
|
|
||||||
// If we still have items in the switched stack, consider ourselves still 'switched'.
|
// If we still have items in the switched stack, consider ourselves still 'switched'.
|
||||||
$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
|
$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,6 +625,7 @@ function restore_current_blog() {
|
||||||
} else {
|
} else {
|
||||||
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
|
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
|
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,16 @@ if ( is_multisite() ) :
|
||||||
$this->assertFalse( $site );
|
$this->assertFalse( $site );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 50391
|
||||||
|
*/
|
||||||
|
public function test_get_blog_details_does_not_switch_to_current_blog() {
|
||||||
|
$count = did_action( 'switch_blog' );
|
||||||
|
|
||||||
|
get_blog_details();
|
||||||
|
$this->assertSame( $count, did_action( 'switch_blog' ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider data_get_all
|
* @dataProvider data_get_all
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue