WordPress.org

Ready to get started?Download WordPress

Codex

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

WPMU Functions/get user id from string

Description

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');

Parameters

$string
(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

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

Usage

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

Examples

<?php
  $useremail 
'user@example.com';
  
$userid get_user_id_from_string$useremail );
  if (
$userid !== null) {
    echo 
'User '.$useremail.' has the user ID of '.$userid;
  } else {
    echo 
'User '.$useremail.' not found.';
  }
?>