From 050e4f26e9cf20f658ffe05b943f3395cd2ffb4e Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 4 Feb 2014 04:12:52 +0000 Subject: [PATCH] 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 --- src/wp-includes/ms-functions.php | 3 +++ tests/phpunit/tests/ms.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index b7b4b6af35..43c23113a3 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -277,6 +277,9 @@ function remove_user_from_blog($user_id, $blog_id = '', $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->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(); diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index 123d866cea..038492a13e 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -25,6 +25,20 @@ class Tests_MS extends WP_UnitTestCase { $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 */