get_userdata( int $user_id )

Retrieve user info by user ID.

Description Description

Parameters Parameters


(int) (Required) User ID

Top ↑

Return Return

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

Top ↑

Source Source

File: wp-includes/pluggable.php

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

Top ↑

Changelog Changelog

Version Description
0.71 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    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.