Changeset 54940
- Timestamp:
- 12/06/2022 01:52:02 PM (23 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/user.php
r54891 r54940 1874 1874 * @since 3.0.0 1875 1875 * @since 4.4.0 'clean_user_cache' action was added. 1876 * @since 6.2.0 User metadata caches are now cleared. 1876 1877 * 1877 1878 * @param WP_User|int $user User object or ID to be cleaned from the cache … … 1893 1894 wp_cache_delete( $user->user_email, 'useremail' ); 1894 1895 } 1896 1897 wp_cache_delete( $user->ID, 'user_meta' ); 1895 1898 1896 1899 /** -
trunk/tests/phpunit/tests/meta/updateMetadata.php
r46586 r54940 28 28 $this->assertSame( 'baz', $found ); 29 29 } 30 31 /** 32 * @ticket 54316 33 * 34 * @group user 35 * 36 * @covers ::clean_user_cache 37 * 38 * @global wpdb $wpdb WordPress database abstraction object. 39 */ 40 public function test_clear_user_metadata_caches() { 41 global $wpdb; 42 43 $user_id = self::factory()->user->create(); 44 45 update_metadata( 'user', $user_id, 'key', 'value1' ); 46 47 $found = get_metadata( 'user', $user_id, 'key', true ); 48 $this->assertSame( 'value1', $found ); 49 50 // Simulate updating the DB from outside of WordPress. 51 $wpdb->update( 52 $wpdb->usermeta, 53 array( 54 'meta_value' => 'value2', 55 ), 56 array( 57 'user_id' => $user_id, 58 'meta_key' => 'key', 59 ) 60 ); 61 62 // Clear the user caches. 63 clean_user_cache( $user_id ); 64 65 // Verify metadata cache was cleared. 66 $found = get_metadata( 'user', $user_id, 'key', true ); 67 $this->assertSame( 'value2', $found ); 68 } 69 70 /** 71 * @ticket 54316 72 * 73 * @group user 74 * 75 * @covers ::clean_user_cache 76 * 77 * @global wpdb $wpdb WordPress database abstraction object. 78 */ 79 public function test_clear_post_metadata_caches() { 80 global $wpdb; 81 82 $post_id = self::factory()->post->create(); 83 84 update_metadata( 'post', $post_id, 'key', 'value1' ); 85 86 $found = get_metadata( 'post', $post_id, 'key', true ); 87 $this->assertSame( 'value1', $found ); 88 89 // Simulate updating the DB from outside of WordPress. 90 $wpdb->update( 91 $wpdb->postmeta, 92 array( 93 'meta_value' => 'value2', 94 ), 95 array( 96 'post_id' => $post_id, 97 'meta_key' => 'key', 98 ) 99 ); 100 101 // Clear the post caches. 102 clean_post_cache( $post_id ); 103 104 // Verify metadata cache was cleared. 105 $found = get_metadata( 'post', $post_id, 'key', true ); 106 $this->assertSame( 'value2', $found ); 107 } 108 30 109 }
Note: See TracChangeset
for help on using the changeset viewer.