Changeset 11611
- Timestamp:
- 06/23/2017 05:32:04 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/bp-members-functions.php
r11447 r11611 207 207 * @since 1.2.0 208 208 * 209 * @param int $user_id The ID of the user.210 * @return array 209 * @param int $user_id The ID of the user. 210 * @return array|bool Array of data on success, boolean false on failure. 211 211 */ 212 212 function bp_core_get_core_userdata( $user_id = 0 ) { … … 215 215 } 216 216 217 if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) { 217 $userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ); 218 219 // No cache. 220 if ( false === $userdata ) { 218 221 $userdata = BP_Core_User::get_core_userdata( $user_id ); 219 wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' ); 222 223 // Cache data; no-result is cached as integer 0. 224 wp_cache_set( 'bp_core_userdata_' . $user_id, false === $userdata ? 0 : $userdata, 'bp' ); 225 226 // Cached no-result, so set return value as false as expected. 227 } elseif ( 0 === $userdata ) { 228 $userdata = false; 220 229 } 221 230 … … 225 234 * @since 1.2.0 226 235 * 227 * @param array $userdata Array of user data for a passed user.236 * @param array|bool $userdata Array of user data for a passed user on success, boolean false on failure. 228 237 */ 229 238 return apply_filters( 'bp_core_get_core_userdata', $userdata ); -
trunk/tests/phpunit/testcases/members/cache.php
r11101 r11611 79 79 $this->assertSame( $num_queries, $wpdb->num_queries ); 80 80 } 81 82 /** 83 * @group bp_core_get_core_userdata 84 */ 85 public function test_bp_core_get_core_userdata_should_cache_no_results() { 86 // Get the userdata for a user that doesn't exist. 87 bp_core_get_core_userdata( PHP_INT_MAX ); 88 89 // Assert that the non-existent user's attempt was cached. 90 $this->assertNotFalse( wp_cache_get( 'bp_core_userdata_' . PHP_INT_MAX, 'bp' ) ); 91 } 81 92 } 82 93
Note: See TracChangeset
for help on using the changeset viewer.