Get WordPress User data By Username Or Login

In your theme code or plugin code, if you know the user name or user login of the WordPress user, you can easily obtain all the user information stored in WordPress database using the below function.

Function

get_userdatabylogin(‘username/login name’)

How to use this function

$username is the variable in which you have the username or login name of the user.

$userinfo = get_userdatabylogin($username);

How to access various user information fields

Remember that the output $userinfo is a ‘Object’ and not an array. I have put all the user fields you get by the execution of this function in the $userinfo object.

Field Description

Field

User ID, this is a numeric unique user id of the user e.g. 4

$userinfo->ID

The login name or user name of the user which he/she uses to log in to WordPress

$userinfo->user_login

The WordPress Hash generated password. Remember that it is not the actual password that user uses to login. It is the hash generated password using the function wp_hash_password()

$userinfo->user_pass

This is the sanitized version of the username, for example the user name is ‘Sanjeev Mishra’, then WordPress creates a username slug as ‘sanjeev-mishra’ which is used in the author page links and so on. This slug or sanitized username is called user_nicename

$userinfo->user_nicename

Email of the user

$userinfo->user_email

The Website of the user entered in the ‘Profile’ section of the WP-admin

$userinfo->user_url

The Timestamp when user has registered

$userinfo->user_registered

This is the user activation key, mostly useful before the user registration is activated

$userinfo->user_activation_key

User Status, it does not seem to have any significance in the recent WordPress versions

$userinfo->user_status

This is the ‘Display Name’ user has selected in the Profile section on admin panel.

$userinfo->display_name

This is the First Name of the user inputted thru the Profile section on admin panel.

$userinfo->first_name

This is the Last Name of the user inputted thru the Profile section on admin panel.

$userinfo->last_name

This is the Nick Name of the user inputted thru the Profile section on admin panel.

$userinfo->nickname

Description of the user inputted thru the Profile section on admin panel.

$userinfo->description

The user_level which indicates the authority of the user on the blog. You can refer WordPress User Level Guide for more details

$userinfo->user_level

The admin color scheme the user has selected ‘fresh’ or ‘classic’

$userinfo->admin_color

The primary blog of user, mostly useful on WPMU. Usually not populated for normal WordPress installation

$userinfo->primary_blog

‘true’ or ‘false’ -> Denotes that whether the Visual Editor is enabled or disabled for the user. Value equal to ‘true’ indicates that visual editor is enabled

$userinfo->rich_editing

6 Comments

  1. Vijendra Mishra

    February 26, 2010 at 2:30 pm

    Nice Article Tejaswini… can we export this user data in to excel format??

  2. Ethan

    February 27, 2010 at 1:11 am

    This is going to be really useful when I go to design a “about logged in user” page next week. Thanks!

  3. NavaPavan

    March 3, 2010 at 1:47 pm

    Is it flaw of wordpress? Then hat about the security

  4. Martine

    March 23, 2010 at 11:55 pm

    Hoi,

    Hoe kan ik de toepassing van deze code en maken het werken in WordPress? Weet iemand een WordPress plugin die extra vraag velden voor de registratie van commenters voegt daaraan toe? Is er een WordPress-plugin om een uitgebreid profiel door zelfgemaakte vragen voor commenters? Bedankt!

  5. niraj

    April 16, 2010 at 8:46 pm

    Ok!
    where to use these commands?

  6. Thank you very much Great post…thanks for share this. ………

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>