Changeset 8532
- Timestamp:
- 06/15/2014 08:07:22 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/bp-members-functions.php
r8333 r8532 196 196 197 197 /** 198 * Return the user _id for a user based on theiruser_login.199 * 200 * @ todo Refactor to check relevant WP caches, or to use get_user_by()201 * 202 * @param string $username Usernameto check.203 * @return int| bool The ID of the matched user, or false.198 * Return the user ID based on a user's user_login. 199 * 200 * @since BuddyPress (1.0.0) 201 * 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 ) ) 209 return false; 210 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 } 213 214 /** 215 * Returns the user_id for a user based on their user_nicename. 216 * 217 * @todo Refactor to check relevant WP caches, or to use get_user_by() 218 * 219 * @param string $username Username to check. 220 * @return int|bool The ID of the matched user, or false. 206 if ( empty( $username ) ) { 207 return false; 208 } 209 210 $user = get_user_by( 'login', $username ); 211 212 return apply_filters( 'bp_core_get_userid', ! empty( $user->ID ) ? $user->ID : NULL, $username ); 213 } 214 215 /** 216 * Return the user ID based on a user's user_nicename. 217 * 218 * @since BuddyPress (1.2.3) 219 * 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 ) ) 226 return false; 227 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 ); 224 if ( empty( $user_nicename ) ) { 225 return false; 226 } 227 228 $user = get_user_by( 'slug', $user_nicename ); 229 230 return apply_filters( 'bp_core_get_userid_from_nicename', ! empty( $user->ID ) ? $user->ID : NULL, $user_nicename ); 229 231 } 230 232 -
trunk/tests/phpunit/testcases/members/functions.php
r8333 r8532 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 }
Note: See TracChangeset
for help on using the changeset viewer.