Codex

WPMU Functions/get user id from string

Contents

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 of. May be either the user's log in (their username), or the email address registered in WordPress.
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.';
  }
?>