WordPress.org

Make WordPress Core

Changeset 36482


Ignore:
Timestamp:
02/05/2016 07:02:51 PM (6 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r36306 r36482  
    16831683
    16841684    wp_cache_delete( $user['user_email'], 'useremail' );
     1685    wp_cache_delete( $user['user_nicename'], 'userslugs' );
    16851686
    16861687    // Merge old and new fields with new fields overwriting old ones.
  • trunk/tests/phpunit/tests/user.php

    r35772 r36482  
    901901
    902902        $this->assertWPError( $u );
     903    }
     904
     905    /**
     906     * @ticket 35750
     907     */
     908    public function test_wp_update_user_should_delete_userslugs_cache() {
     909        $u = self::factory()->user->create();
     910        $user = get_userdata( $u );
     911
     912        wp_update_user( array(
     913            'ID' => $u,
     914            'user_nicename' => 'newusernicename',
     915        ) );
     916        $updated_user = get_userdata( $u );
     917
     918        $this->assertFalse( wp_cache_get( $user->user_nicename, 'userslugs' ) );
     919        $this->assertEquals( $u, wp_cache_get( $updated_user->user_nicename, 'userslugs' ) );
    903920    }
    904921
Note: See TracChangeset for help on using the changeset viewer.