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 */