Oliver Spryn
Oliver Spryn

Reputation: 17358

Wordpress Get First and Last Name

I am trying to get the first name of a user in Wordpress by using the following code:

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

... and my output is at the end of the post.

According the documentation, I should be able to fetch the user's first and last name. However, mimicking their example would be fruitless, since neither user_firstname nor user_lastname show up in this variable dump

Any ideas on why not? I am using Wordpress 3.5.1 and my WP account does have the first and last name set.

Thank you for your time.

Output:

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

Upvotes: 0

Views: 793

Answers (1)

Oliver Spryn
Oliver Spryn

Reputation: 17358

Whoa! It is randomly working now.

  1. Set first and last name under "My Account"
  2. Log out
  3. Log back in
  4. Walk away for 30 mins
  5. Do another var_dump()

Now, I'm a Computer Science major, and I've never seen computer magic until now.

But seriously, probably was retaining old cookies regarding my user info until I logged out and then back in.

Upvotes: 0

Related Questions