Changeset 53818
- Timestamp:
- 08/03/2022 02:34:58 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-object-cache.php
r53767 r53818 131 131 132 132 /** 133 * Serves as a utility function to determine whether a key is valid. 134 * 135 * @since 6.1.0 136 * 137 * @param int|string $key Cache key to check for validity. 138 * @return bool Whether the key is valid. 139 */ 140 protected function is_valid_key( $key ) { 141 if ( is_int( $key ) ) { 142 return true; 143 } 144 145 if ( is_string( $key ) && trim( $key ) !== '' ) { 146 return true; 147 } 148 149 $type = gettype( $key ); 150 151 if ( ! function_exists( '__' ) ) { 152 wp_load_translations_early(); 153 } 154 155 $message = is_string( $key ) 156 ? __( 'Cache key must not be an empty string.' ) 157 /* translators: %s: The type of the given cache key. */ 158 : sprintf( __( 'Cache key must be integer or non-empty string, %s given.' ), $type ); 159 160 _doing_it_wrong( 161 sprintf( '%s::%s', __CLASS__, debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1]['function'] ), 162 $message, 163 '6.1.0' 164 ); 165 166 return false; 167 } 168 169 /** 133 170 * Serves as a utility function to determine whether a key exists in the cache. 134 171 * … … 164 201 } 165 202 203 if ( ! $this->is_valid_key( $key ) ) { 204 return false; 205 } 206 166 207 if ( empty( $group ) ) { 167 208 $group = 'default'; … … 217 258 */ 218 259 public function replace( $key, $data, $group = 'default', $expire = 0 ) { 260 if ( ! $this->is_valid_key( $key ) ) { 261 return false; 262 } 263 219 264 if ( empty( $group ) ) { 220 265 $group = 'default'; … … 246 291 * 247 292 * @since 2.0.0 293 * @since 6.1.0 Returns false if cache key is invalid. 248 294 * 249 295 * @param int|string $key What to call the contents in the cache. … … 251 297 * @param string $group Optional. Where to group the cache contents. Default 'default'. 252 298 * @param int $expire Optional. Not used. 253 * @return true Always returns true.299 * @return bool True if contents were set, false if key is invalid. 254 300 */ 255 301 public function set( $key, $data, $group = 'default', $expire = 0 ) { 302 if ( ! $this->is_valid_key( $key ) ) { 303 return false; 304 } 305 256 306 if ( empty( $group ) ) { 257 307 $group = 'default'; … … 311 361 */ 312 362 public function get( $key, $group = 'default', $force = false, &$found = null ) { 363 if ( ! $this->is_valid_key( $key ) ) { 364 return false; 365 } 366 313 367 if ( empty( $group ) ) { 314 368 $group = 'default'; … … 369 423 */ 370 424 public function delete( $key, $group = 'default', $deprecated = false ) { 425 if ( ! $this->is_valid_key( $key ) ) { 426 return false; 427 } 428 371 429 if ( empty( $group ) ) { 372 430 $group = 'default'; … … 417 475 */ 418 476 public function incr( $key, $offset = 1, $group = 'default' ) { 477 if ( ! $this->is_valid_key( $key ) ) { 478 return false; 479 } 480 419 481 if ( empty( $group ) ) { 420 482 $group = 'default'; … … 456 518 */ 457 519 public function decr( $key, $offset = 1, $group = 'default' ) { 520 if ( ! $this->is_valid_key( $key ) ) { 521 return false; 522 } 523 458 524 if ( empty( $group ) ) { 459 525 $group = 'default'; -
trunk/src/wp-includes/user.php
r53501 r53818 1851 1851 wp_cache_add( $user->ID, $user, 'users' ); 1852 1852 wp_cache_add( $user->user_login, $user->ID, 'userlogins' ); 1853 wp_cache_add( $user->user_email, $user->ID, 'useremail' );1854 1853 wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' ); 1854 1855 if ( ! empty( $user->user_email ) ) { 1856 wp_cache_add( $user->user_email, $user->ID, 'useremail' ); 1857 } 1855 1858 } 1856 1859 … … 1879 1882 wp_cache_delete( $user->ID, 'users' ); 1880 1883 wp_cache_delete( $user->user_login, 'userlogins' ); 1881 wp_cache_delete( $user->user_email, 'useremail' );1882 1884 wp_cache_delete( $user->user_nicename, 'userslugs' ); 1885 1886 if ( ! empty( $user->user_email ) ) { 1887 wp_cache_delete( $user->user_email, 'useremail' ); 1888 } 1883 1889 1884 1890 /** -
trunk/tests/phpunit/tests/user.php
r53698 r53818 2011 2011 'ID' => $create_user, 2012 2012 'user_login' => 'test_user', 2013 'user_email' => 'user@example.com', 2013 2014 'meta_input' => array( 2014 2015 'test_meta_key' => 'test_meta_updated', -
trunk/tests/phpunit/tests/user/getUserCount.php
r53011 r53818 46 46 47 47 // Add another user to fake the network user count to be different. 48 wpmu_create_user( 'user', 'pass', ' email' );48 wpmu_create_user( 'user', 'pass', 'user@example.com' ); 49 49 50 50 wp_update_network_user_counts( $different_network_id ); … … 69 69 $start_count = get_user_count(); 70 70 71 wpmu_create_user( 'user', 'pass', ' email' );71 wpmu_create_user( 'user', 'pass', 'user@example.com' ); 72 72 73 73 // No change, cache not refreshed. … … 133 133 $current_network_user_count = get_user_count(); 134 134 135 $u1 = wpmu_create_user( 'user', 'pass', ' email' );135 $u1 = wpmu_create_user( 'user', 'pass', 'user@example.com' ); 136 136 137 137 $user_count = get_user_count(); -
trunk/tests/phpunit/tests/user/slashes.php
r53557 r53818 149 149 'user_login' => 'slash_example_user_3', 150 150 'role' => 'subscriber', 151 ' email'=> 'user3@example.com',151 'user_email' => 'user3@example.com', 152 152 'first_name' => self::SLASH_1, 153 153 'last_name' => self::SLASH_3, … … 170 170 'user_login' => 'slash_example_user_4', 171 171 'role' => 'subscriber', 172 ' email' => 'user3@example.com',172 'user_email' => 'user4@example.com', 173 173 'first_name' => self::SLASH_2, 174 174 'last_name' => self::SLASH_4,
Note: See TracChangeset
for help on using the changeset viewer.