get_userdata( int $user_id ): WP_User|false

Retrieves user info by user ID.

Parameters

$user_idintrequired
User ID

Return

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

Source

function get_userdata( $user_id ) {
	return get_user_by( 'id', $user_id );
}

Changelog

VersionDescription
0.71Introduced.

User Contributed Notes

  1. Skip to note 4 content

    Basic Usage
    The get_userdata() function returns an object of the user’s data. You can echo various parts of the returned object or loop through the data to display it all.

    Example displaying certain parts:

    <?php $user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";
    ?>

    Results in:

    Username: admin
    User roles: administrator
    User ID: 1

    You can also assign certain parts into individual variables for displaying later or in multiple places.

    Example for extracting certain parts:

    <?php $user_info = get_userdata(1);
          $username = $user_info->user_login;
          $first_name = $user_info->first_name;
          $last_name = $user_info->last_name;
          echo "$first_name $last_name logs into her WordPress site with the user name of $username.";
    ?>

    Results in:

    Harriet Smith logs into her WordPress site with the user name of mrssmith.

You must log in before being able to contribute a note or feedback.