get_user_id_from_string

Get a numeric user ID from either an email address or a login.

Description

(int) get_user_id_from_string( (string) $string ); 

A numeric string is considered to be an existing user ID and is simply returned as such.

Returns (int)

Parameters (1)

0. $string (string)
Either an email address or a login.

Usage

  1. if ( !function_exists( 'get_user_id_from_string' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-deprecated.php'; 
  3.  
  4. // Either an email address or a login. 
  5. $string = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_user_id_from_string($string); 
  9.  

Defined (1)

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

/wp-includes/ms-deprecated.php  
  1. function get_user_id_from_string( $string ) { 
  2. _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' ); 
  3.  
  4. if ( is_email( $string ) ) 
  5. $user = get_user_by( 'email', $string ); 
  6. elseif ( is_numeric( $string ) ) 
  7. return $string; 
  8. else 
  9. $user = get_user_by( 'login', $string ); 
  10.  
  11. if ( $user ) 
  12. return $user->ID; 
  13. return 0;