Skip to content

Use get_sites in get_blog_details#3928

Open
spacedmonkey wants to merge 4 commits intoWordPress:trunkfrom
spacedmonkey:fix/get_blog_details
Open

Use get_sites in get_blog_details#3928
spacedmonkey wants to merge 4 commits intoWordPress:trunkfrom
spacedmonkey:fix/get_blog_details

Conversation

@spacedmonkey
Copy link
Member

Trac ticket: https://core.trac.wordpress.org/ticket/40228


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@spacedmonkey spacedmonkey self-assigned this Jan 27, 2023
if ( ! $get_all ) {
wp_cache_set( $blog_id . $all, $details, 'blog-details' );
return $details;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixarntz Pretty sure that this is not needed anymore

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();
	}

as this is done here.

private function get_details() {
$details = wp_cache_get( $this->blog_id, 'site-details' );
if ( false === $details ) {
switch_to_blog( $this->blog_id );
// Create a raw copy of the object for backward compatibility with the filter below.
$details = new stdClass();
foreach ( get_object_vars( $this ) as $key => $value ) {
$details->$key = $value;
}
$details->blogname = get_option( 'blogname' );
$details->siteurl = get_option( 'siteurl' );
$details->post_count = get_option( 'post_count' );
$details->home = get_option( 'home' );
restore_current_blog();
wp_cache_set( $this->blog_id, $details, 'site-details' );
}
/** This filter is documented in wp-includes/ms-blogs.php */
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
/**
* Filters a site's extended properties.
*
* @since 4.6.0
*
* @param stdClass $details The site details.
*/
$details = apply_filters( 'site_details', $details );
return $details;
}

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacedmonkey While technically speaking the changes here look reasonable, I believe they do not address the main problem voiced in https://core.trac.wordpress.org/ticket/40228#comment:33.

A fix for this was already committed 5 years ago but then reverted due to this feedback. Therefore we must not ignore it. It looks like we need to keep supporting the existing cache groups in order to make this change in a way that does not break backward compatibility for larger multisites that rely on this caching to work.

I made that mistake in https://core.trac.wordpress.org/changeset/41719, and we should not repeat it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants