When updating a user, invalidate its 'userslugs' cache.

`user_nicename` can be changed via `wp_update_user()`, so we invalidate just
to be safe.

Props thebrandonallen.
Fixes #35750.

git-svn-id: https://develop.svn.wordpress.org/trunk@36482 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-02-05 19:02:51 +00:00
parent 2c73fd9531
commit 3ed7c823c9
2 changed files with 18 additions and 0 deletions

View File

@ -1682,6 +1682,7 @@ function wp_update_user($userdata) {
}
wp_cache_delete( $user['user_email'], 'useremail' );
wp_cache_delete( $user['user_nicename'], 'userslugs' );
// Merge old and new fields with new fields overwriting old ones.
$userdata = array_merge( $user, $userdata );

View File

@ -902,6 +902,23 @@ class Tests_User extends WP_UnitTestCase {
$this->assertWPError( $u );
}
/**
* @ticket 35750
*/
public function test_wp_update_user_should_delete_userslugs_cache() {
$u = self::factory()->user->create();
$user = get_userdata( $u );
wp_update_user( array(
'ID' => $u,
'user_nicename' => 'newusernicename',
) );
$updated_user = get_userdata( $u );
$this->assertFalse( wp_cache_get( $user->user_nicename, 'userslugs' ) );
$this->assertEquals( $u, wp_cache_get( $updated_user->user_nicename, 'userslugs' ) );
}
function test_changing_email_invalidates_password_reset_key() {
global $wpdb;