1). get_currentuserinfo();
此函数将当前登录用户信息赋给全局变量$current_user以及一些单独的用户信息全局变量例如$display_name, $user_email等。 如下:
<?php
global $current_user, $display_name , $user_email;
get_currentuserinfo();
//全局变量$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";
//单独的全局变量
echo $display_name . "'s email address is: " . $user_email;
?>
2). wp_get_current_user()
此函数必须将返回值赋给一个数组变量,代码如下:
<?php
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
} else {
// Logged in.
}
?>
日志链接:http://blog.ui90.com/wordpress-access-to-current-login-user-information.html
博客名称:胖子马博客