get_user_by() – Retrieve user info by a given field

You appear to be a bot. Output may be restricted

Description

Retrieve user info by a given field

Usage

$WP_User|false = get_user_by( $field, $value );

Parameters

$field
( string ) required

$value
( int|string ) required – A value for $field. A user ID, slug, email address, or login name.

Returns

WP_User|false WP_User object on success, false on failure.

Source

File name: wordpress/wp-includes/pluggable.php
Lines:

1 to 18 of 18
  function get_user_by( $field, $value ) {
    global $current_user;

    $userdata = WP_User::WP_User::get_data_by( $field, $value );

    if ( ! $userdata ) {
      return false;
    }

    if ( $current_user instanceof WP_User && $current_user->ID === (int) $userdata->ID ) {
      return $current_user;
    }

    $user = new WP_User;
    $user->init( $userdata );

    return $user;
  }
 

 View on GitHub View on Trac

Published:

Last updated:

12th September 2021

Information

API Letters: ,,
The field to retrieve the user with. id ID slug email login.