Wordpress获取名字和姓氏

时间:2013-03-25 21:01:27

标签: php wordpress

我正在尝试使用以下代码获取Wordpress中用户的名字:

global $current_user;
get_currentuserinfo();
var_dump($current_user);

...我的输出结尾是帖子。

根据the documentation,我应该能够获取用户的名字和姓氏。但是,模仿他们的例子将毫无结果,因为user_firstnameuser_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

1 个答案:

答案 0 :(得分:0)

哇!它现在随机工作。

  1. 在“我的帐户”
  2. 下设置名字和姓氏
  3. 退出
  4. 重新登录
  5. 走开30分钟
  6. 做另一个var_dump()
  7. 现在,我是计算机科学专业的学生,​​直到现在我才从未见过电脑魔术。

    但严重的是,在我退出然后重新登录之前,可能会保留关于我的用户信息的旧cookie。