Ticket #5696: 5696.01.patch
File 5696.01.patch, 2.6 KB (added by , 11 years ago) |
---|
-
src/bp-members/bp-members-functions.php
195 195 } 196 196 197 197 /** 198 * Return the user _id for a user based on theiruser_login.198 * Return the user ID based on a user's user_login. 199 199 * 200 * @ todo Refactor to check relevant WP caches, or to use get_user_by()200 * @since BuddyPress (1.0.0) 201 201 * 202 * @param string $username Usernameto check.203 * @return int| bool The ID of the matched user, or false.202 * @param string $username user_login to check. 203 * @return int|null The ID of the matched user on success, null on failure. 204 204 */ 205 205 function bp_core_get_userid( $username ) { 206 global $wpdb; 207 208 if ( empty( $username ) ) 206 if ( empty( $username ) ) { 209 207 return false; 208 } 209 210 $user = get_user_by( 'login', $username ); 210 211 211 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->users} WHERE user_login = %s", $username ) ), $username );212 return apply_filters( 'bp_core_get_userid', ! empty( $user->ID ) ? $user->ID : NULL, $username ); 212 213 } 213 214 214 215 /** 215 * Return s the user_id for a user based on theiruser_nicename.216 * Return the user ID based on a user's user_nicename. 216 217 * 217 * @ todo Refactor to check relevant WP caches, or to use get_user_by()218 * @since BuddyPress (1.2.3) 218 219 * 219 * @param string $user name Username to check.220 * @return int| bool The ID of the matched user, or false.220 * @param string $user_nicename user_nicename to check. 221 * @return int|null The ID of the matched user on success, null on failure. 221 222 */ 222 223 function bp_core_get_userid_from_nicename( $user_nicename ) { 223 global $wpdb; 224 225 if ( empty( $user_nicename ) ) 224 if ( empty( $user_nicename ) ) { 226 225 return false; 226 } 227 228 $user = get_user_by( 'slug', $user_nicename ); 227 229 228 return apply_filters( 'bp_core_get_userid_from_nicename', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s", $user_nicename ) ), $user_nicename );230 return apply_filters( 'bp_core_get_userid_from_nicename', ! empty( $user->ID ) ? $user->ID : NULL, $user_nicename ); 229 231 } 230 232 231 233 /** -
tests/phpunit/testcases/members/functions.php
399 399 400 400 $this->assertSame( $expected, $found ); 401 401 } 402 403 /** 404 * @group bp_core_get_userid_from_nicename 405 */ 406 public function test_bp_core_get_userid_from_nicename_failure() { 407 $this->assertSame( NULL, bp_core_get_userid_from_nicename( 'non_existent_user' ) ); 408 } 402 409 }