bp_core_get_userid

Return the user ID based on a user's user_login.

Description

(int|null) bp_core_get_userid( (string) $username = '' ); 

Returns (int|null)

The ID of the matched user on success, null on failure.

Parameters (1)

0. $username — Optional. (string) => ''
User_login to check.

Usage

  1. if ( !function_exists( 'bp_core_get_userid' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4. // user_login to check. 
  5. $username = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_get_userid($username); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-functions.php  
  1. function bp_core_get_userid( $username = '' ) { 
  2. if ( empty( $username ) ) { 
  3. return false; 
  4.  
  5. $user = get_user_by( 'login', $username ); 
  6.  
  7. /** 
  8. * Filters the ID of a user, based on user_login. 
  9. * @since 1.0.1 
  10. * @param int|null $value ID of the user or null. 
  11. * @param string $username User login to check. 
  12. */ 
  13. return apply_filters( 'bp_core_get_userid', ! empty( $user->ID ) ? $user->ID : NULL, $username );