$current_user = wp_get_current_user(); echo $current_user->ID; echo $current_user->user_login; echo $current_user->user_email;
$user = new WP_User(2); echo $user->user_login; echo $user->user_email;
$user = wp_get_current_user(); if (in_array('administrator', $user->roles)) { echo "This user is an administrator."; }This code gets the current user's information and then checks if they have the 'administrator' role. If they do, it echoes a message. Package library: WordPress Core Overall, WP_User is a useful class for working with users in WordPress. It is included in the WordPress Core package library.