[wp-trac] [WordPress Trac] #50391: Unnecessary switch_to_blog() in get_blog_details()
WordPress Trac
noreply at wordpress.org
Mon Jun 15 11:11:16 UTC 2020
#50391: Unnecessary switch_to_blog() in get_blog_details()
----------------------------------------+------------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.5
Component: Networks and Sites | Version:
Severity: normal | Resolution:
Keywords: needs-patch good-first-bug | Focuses: multisite
----------------------------------------+------------------------
Changes (by SergeyBiryukov):
* keywords: => needs-patch good-first-bug
Comment:
Replying to [comment:1 arpitgshah]:
> Do we need to remove this action or need to get all the details with new
blog?
Thanks for your interest!
We need to only perform the switch if `$blog_id` is different from the
current blog ID. Something like this:
{{{
$switched_blog = false;
if ( get_current_blog_id() !== $blog_id ) {
switch_to_blog( $blog_id );
$switched_blog = true;
}
$details->blogname = get_option( 'blogname' );
$details->siteurl = get_option( 'siteurl' );
$details->post_count = get_option( 'post_count' );
$details->home = get_option( 'home' );
if ( $switched_blog ) {
restore_current_blog();
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50391#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list