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 |