Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

WPMU Functions/get user id from string


Returns the user ID of the user specified by either username or registered email address. In order to use this function in plugins, you must include the containing WordPress file using the following: require_once(ABSPATH . WPINC . '/ms-functions.php');


(string) (required) String representation of the user to lookup the ID for. May be either the user's login (their username), or the email address registered in WordPress. A numeric string is considered to be an existing user ID and is simply returned as such.
Default: None

Return Values

ID of the user specified by $string on success, null if no user is found.


<?php get_user_id_from_string'user@example.com' ); ?>


$userid get_user_id_from_string$useremail );
  if (
$userid !== null) {
'User '.$useremail.' has the user ID of '.$userid;
  } else {
'User '.$useremail.' not found.';