我正在尝试使用以下代码在 Wordpress 中获取用户的名字:
global $current_user;
get_currentuserinfo();
var_dump($current_user);
...我的输出在帖子的末尾。
根据文档,我应该能够获取用户的名字和姓氏。然而,模仿他们的例子是徒劳的,因为在这个变量转储中既没有user_firstname
也没有user_lastname
出现
关于为什么不的任何想法?我正在使用 Wordpress 3.5.1,我的 WP 帐户确实设置了名字和姓氏。
感谢您的时间。
输出:
object(WP_User)[113]
public 'data' =>
object(stdClass)[115]
public 'ID' => string '1' (length=1)
public 'user_login' => string 'stuff' (length=16)
public 'user_pass' => string 'stuff' (length=34)
public 'user_nicename' => string 'stuff' (length=15)
public 'user_email' => string 'stuff' (length=16)
public 'user_url' => string '' (length=0)
public 'user_registered' => string '2013-03-24 16:54:43' (length=19)
public 'user_activation_key' => string '' (length=0)
public 'user_status' => string '0' (length=1)
public 'display_name' => string 'stuff' (length=12)
public 'ID' => int 1
public 'caps' =>
array (size=1)
'administrator' => boolean true
public 'cap_key' => string 'wp_capabilities' (length=15)
public 'roles' =>
array (size=1)
0 => string 'administrator' (length=13)
public 'allcaps' =>
array (size=63)
'switch_themes' => boolean true
'edit_themes' => boolean true
'activate_plugins' => boolean true
'edit_plugins' => boolean true
'edit_users' => boolean true
'edit_files' => boolean true
'manage_options' => boolean true
'moderate_comments' => boolean true
'manage_categories' => boolean true
'manage_links' => boolean true
'upload_files' => boolean true
'import' => boolean true
'unfiltered_html' => boolean true
'edit_posts' => boolean true
'edit_others_posts' => boolean true
'edit_published_posts' => boolean true
'publish_posts' => boolean true
'edit_pages' => boolean true
'read' => boolean true
'level_10' => boolean true
'level_9' => boolean true
'level_8' => boolean true
'level_7' => boolean true
'level_6' => boolean true
'level_5' => boolean true
'level_4' => boolean true
'level_3' => boolean true
'level_2' => boolean true
'level_1' => boolean true
'level_0' => boolean true
'edit_others_pages' => boolean true
'edit_published_pages' => boolean true
'publish_pages' => boolean true
'delete_pages' => boolean true
'delete_others_pages' => boolean true
'delete_published_pages' => boolean true
'delete_posts' => boolean true
'delete_others_posts' => boolean true
'delete_published_posts' => boolean true
'delete_private_posts' => boolean true
'edit_private_posts' => boolean true
'read_private_posts' => boolean true
'delete_private_pages' => boolean true
'edit_private_pages' => boolean true
'read_private_pages' => boolean true
'delete_users' => boolean true
'create_users' => boolean true
'unfiltered_upload' => boolean true
'edit_dashboard' => boolean true
'update_plugins' => boolean true
'delete_plugins' => boolean true
'install_plugins' => boolean true
'update_themes' => boolean true
'install_themes' => boolean true
'update_core' => boolean true
'list_users' => boolean true
'remove_users' => boolean true
'add_users' => boolean true
'promote_users' => boolean true
'edit_theme_options' => boolean true
'delete_themes' => boolean true
'export' => boolean true
'administrator' => boolean true
public 'filter' => null