Default Usage
The call to get_currentuserinfo() places the current user’s info into $current_user, where it can be retrieved using member variables.
将当前登录用户信息赋给全局变量$current_user
以及一些单独的用户信息全局变量例如$display_name, $user_email
等。
<?php global $current_user;
echo 'Username: ' . $current_user->user_login . "\n";
echo 'User email: ' . $current_user->user_email . "\n";
echo 'User first name: ' . $current_user->user_firstname . "\n";
echo 'User last name: ' . $current_user->user_lastname . "\n";
echo 'User display name: ' . $current_user->display_name . "\n";
echo 'User ID: ' . $current_user->ID . "\n";
?>
或者
<?php
//global $current_user;
$current_user = get_currentuserinfo();
echo 'Username: ' . $current_user->user_login . "\n";
echo 'User email: ' . $current_user->user_email . "\n";
echo 'User first name: ' . $current_user->user_firstname . "\n";
echo 'User last name: ' . $current_user->user_lastname . "\n";
echo 'User display name: ' . $current_user->display_name . "\n";
echo 'User ID: ' . $current_user->ID . "\n";
?>