get_user_by

Retrieve user info by a given field.

Description

(WP_User|false) get_user_by( (string) $field, (int|string) $value ); 

Returns (WP_User|false)

WP_User object on success, false on failure.

Parameters (2)

0. $field (string)
The field to retrieve the user with. id | ID | slug | email | login.
1. $value (int|string)
A value for $field. A user ID, slug, email address, or login name.

Usage

  1. if ( !function_exists( 'get_user_by' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable.php'; 
  3.  
  4. // The field to retrieve the user with. id | ID | slug | email | login. 
  5. $field = ''; 
  6.  
  7. // A value for $field. A user ID, slug, email address, or login name. 
  8. $value = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_user_by($field, $value); 
  12.  

Defined (1)

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

/wp-includes/pluggable.php  
  1. function get_user_by( $field, $value ) { 
  2. $userdata = WP_User::get_data_by( $field, $value ); 
  3.  
  4. if ( !$userdata ) 
  5. return false; 
  6.  
  7. $user = new WP_User; 
  8. $user->init( $userdata ); 
  9.  
  10. return $user;