Invalidate the post cache for posts associated with a user who has been removed from a blog in `remove_user_from_blog()`. Adds a unit test.

Props nprasath002 for the initial patch.
Fixes #25545.



git-svn-id: https://develop.svn.wordpress.org/trunk@27087 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-02-04 04:12:52 +00:00
parent e07424147c
commit 050e4f26e9
2 changed files with 17 additions and 0 deletions

View File

@ -277,6 +277,9 @@ function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
$reassign = (int) $reassign; $reassign = (int) $reassign;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) ); $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) ); $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) );
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $reassign ) );
array_map( 'clean_post_cache', $post_ids );
} }
restore_current_blog(); restore_current_blog();

View File

@ -25,6 +25,20 @@ class Tests_MS extends WP_UnitTestCase {
$wpdb->suppress_errors( $this->suppress ); $wpdb->suppress_errors( $this->suppress );
} }
function test_remove_user_from_blog() {
$user1 = $this->factory->user->create_and_get();
$user2 = $this->factory->user->create_and_get();
$post_id = $this->factory->post->create( array( 'post_author' => $user1->ID ) );
remove_user_from_blog( $user1->ID, 1, $user2->ID );
$post = get_post( $post_id );
$this->assertNotEquals( $user1->ID, $post->post_author );
$this->assertEquals( $user2->ID, $post->post_author );
}
/** /**
* @ticket 22917 * @ticket 22917
*/ */