The get_currentuserinfo() WordPress PHP function populates global variables with information about the currently logged in user.
Usage
global $current_user; get_currentuserinfo(); echo 'Username: ' . esc_html($current_user->user_login) . '<br />';
Parameters
- None
More information
See WordPress Developer Resources: get_currentuserinfo()
- This function is deprecated since WordPress 4.5.0.
- It is recommended to use wp_get_current_user() instead.
Examples
Displaying username
Display the current user’s username.
global $current_user; get_currentuserinfo(); echo 'Username: ' . esc_html($current_user->user_login) . '<br />';
Displaying user email
Display the current user’s email address.
global $current_user; get_currentuserinfo(); echo 'User email: ' . esc_html($current_user->user_email) . '<br />';
Displaying user first name
Display the current user’s first name.
global $current_user; get_currentuserinfo(); echo 'User first name: ' . esc_html($current_user->user_firstname) . '<br />';
Displaying user last name
Display the current user’s last name.
global $current_user; get_currentuserinfo(); echo 'User last name: ' . esc_html($current_user->user_lastname) . '<br />';
Displaying user ID
Display the current user’s ID.
global $current_user; get_currentuserinfo(); echo 'User ID: ' . esc_html($current_user->ID) . '<br />';