Use switch_to_blog()/restore_current_blog() in get_blog_post() and get_blog_permalink(). Eliminate the duplicate caching in these functions. Return WP_Post from get_blog_post(). Update phpdoc. Remove global-posts cache invalidation. Props jondavidjohn fixes #21595
git-svn-id: http://core.svn.wordpress.org/trunk@21628 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
af91b41af3
commit
2ea0626e5d
|
@ -152,17 +152,12 @@ function get_blog_count( $id = 0 ) {
|
||||||
*
|
*
|
||||||
* @param int $blog_id ID of the blog.
|
* @param int $blog_id ID of the blog.
|
||||||
* @param int $post_id ID of the post you're looking for.
|
* @param int $post_id ID of the post you're looking for.
|
||||||
* @return object The post.
|
* @return WP_Post|null WP_Post on success or null on failure
|
||||||
*/
|
*/
|
||||||
function get_blog_post( $blog_id, $post_id ) {
|
function get_blog_post( $blog_id, $post_id ) {
|
||||||
global $wpdb;
|
switch_to_blog( $blog_id );
|
||||||
|
$post = get_post( $post_id );
|
||||||
$key = $blog_id . '-' . $post_id;
|
restore_current_blog();
|
||||||
$post = wp_cache_get( $key, 'global-posts' );
|
|
||||||
if ( $post == false ) {
|
|
||||||
$post = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts WHERE ID = %d', $post_id ) );
|
|
||||||
wp_cache_add( $key, $post, 'global-posts' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
@ -313,19 +308,15 @@ function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
|
||||||
*
|
*
|
||||||
* @since MU 1.0
|
* @since MU 1.0
|
||||||
*
|
*
|
||||||
* @param int $_blog_id ID of the source blog.
|
* @param int $blog_id ID of the source blog.
|
||||||
* @param int $post_id ID of the desired post.
|
* @param int $post_id ID of the desired post.
|
||||||
* @return string The post's permalink
|
* @return string The post's permalink
|
||||||
*/
|
*/
|
||||||
function get_blog_permalink( $_blog_id, $post_id ) {
|
function get_blog_permalink( $blog_id, $post_id ) {
|
||||||
$key = "{$_blog_id}-{$post_id}-blog_permalink";
|
switch_to_blog( $blog_id );
|
||||||
$link = wp_cache_get( $key, 'site-options' );
|
$link = get_permalink( $post_id );
|
||||||
if ( $link == false ) {
|
restore_current_blog();
|
||||||
switch_to_blog( $_blog_id );
|
|
||||||
$link = get_permalink( $post_id );
|
|
||||||
restore_current_blog();
|
|
||||||
wp_cache_add( $key, $link, 'site-options', 360 );
|
|
||||||
}
|
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4517,9 +4517,6 @@ function clean_post_cache( $post ) {
|
||||||
clean_post_cache( $child );
|
clean_post_cache( $child );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_multisite() )
|
|
||||||
wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue