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.
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.
User ID, this is a numeric unique user id of the user e.g. 4
The login name or user name of the user which he/she uses to log in to WordPress
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()
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
Email of the user
The Website of the user entered in the ‘Profile’ section of the WP-admin
The Timestamp when user has registered
This is the user activation key, mostly useful before the user registration is activated
User Status, it does not seem to have any significance in the recent WordPress versions
This is the ‘Display Name’ user has selected in the Profile section on admin panel.
This is the First Name of the user inputted thru the Profile section on admin panel.
This is the Last Name of the user inputted thru the Profile section on admin panel.
This is the Nick Name of the user inputted thru the Profile section on admin panel.
Description of the user inputted thru the Profile section on admin panel.
The user_level which indicates the authority of the user on the blog. You can refer WordPress User Level Guide for more details
The admin color scheme the user has selected ‘fresh’ or ‘classic’
The primary blog of user, mostly useful on WPMU. Usually not populated for normal WordPress installation
‘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