之前Wordpress 4.5 get_currentuserinfo()
是一个可接受的选项,但现在已被弃用,取而代之的是wp_get_current_user()
.
您可以设置wp_get_current_user()
作为一个变量,可以在函数或页面中轻松访问它:
$current_user = wp_get_current_user();
Example:
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
echo \'Username: \' . $current_user->user_login . \'<br />\';
echo \'User email: \' . $current_user->user_email . \'<br />\';
echo \'User first name: \' . $current_user->user_firstname . \'<br />\';
echo \'User last name: \' . $current_user->user_lastname . \'<br />\';
echo \'User display name: \' . $current_user->display_name . \'<br />\';
echo \'User ID: \'. $current_user->ID . \'<br />\';
echo \'User avatar: \' . get_avatar( $current_user->ID, 64 ) . \'<br />\';
} else {
echo \'User not logged in.\';
}
Also, it\'s important to make sure this is all being done after init
to avoid blank output.