title: How to get Wordpress user's first name from WP_User object?
body: <p>I'm writing a basic plugin. Here's my code:</p>
  
  <pre><code>    $new_user = get_userdata($user_id); //$user_id is passed as a parameter
  
  $first_name1 = $new_user-&gt;user_firstname;
  $last_name1 = $new_user-&gt;user_lastname;
      echo "&lt;" . $first_name1 . $last_name1 . "&gt;";
      //returns: &lt;&gt;
  
  $first_name2 = $new_user-first_name;
  $last_name2 = $new_user-&gt;last_name;
      echo "&lt;" . $first_name2 . $last_name2 . "&gt;";
      //returns: &lt;&gt;
  </code></pre>
  
  <p>According to <a href="http://codex.wordpress.org/Function_Reference/get_userdata#Notes" rel="noreferrer">the codex</a>, this should work, but when I echo <code>$first_name</code> or <code>$last_name</code> they're empty. Strangely, <em>THIS</em> does work:</p>
  
  <pre><code>    $id = $new_user-&gt;ID;
  </code></pre>
  
  <p>Am I doing something wrong?</p>
  
  <p>UPDATE:</p>
  
  <p>I <code>var_dump</code>ed  <code>$new_user</code> and those properties aren't in there! Is this because I'm calling it from inside a plugin in the /mu-plugins directory? Do those properties get added later?</p>
  
  <pre><code>object(WP_User)#334 (7) { ["data"]=&gt; object(stdClass)#330 (10) { ["ID"]=&gt; string(3) "758" ["user_login"]=&gt; string(7) "emerson" ["user_pass"]=&gt; string(34) "$P$BB2PuvRbyGUSVZR1M8FLSujPvMO2MW0" ["user_nicename"]=&gt; string(7) "emerson" ["user_email"]=&gt; string(16) "123esl@gmail.com" ["user_url"]=&gt; string(0) "" ["user_registered"]=&gt; string(19) "2012-08-17 01:03:27" ["user_activation_key"]=&gt; string(0) "" ["user_status"]=&gt; string(1) "0" ["display_name"]=&gt; string(7) "emerson" } ["ID"]=&gt; int(758) ["caps"]=&gt; array(1) { ["subscriber"]=&gt; string(1) "1" } ["cap_key"]=&gt; string(15) "wp_capabilities" ["roles"]=&gt; array(1) { [0]=&gt; string(10) "subscriber" } ["allcaps"]=&gt; array(15) { ["read"]=&gt; bool(true) ["level_0"]=&gt; bool(true) ["read_questions"]=&gt; bool(true) ["read_answers"]=&gt; bool(true) ["publish_questions"]=&gt; bool(true) ["immediately_publish_questions"]=&gt; bool(true) ["publish_answers"]=&gt; bool(true) ["read_private_forums"]=&gt; bool(true) ["publish_topics"]=&gt; bool(true) ["edit_topics"]=&gt; bool(true) ["publish_replies"]=&gt; bool(true) ["edit_replies"]=&gt; bool(true) ["assign_topic_tags"]=&gt; bool(true) ["access_s2member_level0"]=&gt; bool(true) ["subscriber"]=&gt; string(1) "1" } ["filter"]=&gt; NULL } 
  </code></pre>
  
  <p>UPDATE2:</p>
  
  <p>I tried this:</p>
  
  <pre><code>$user_meta = get_user_meta( $new_user-&gt;ID );
  var_dump($user_meta);
  </code></pre>
  
  <p>and I got this (last_name and first_name are empty even though they're defined in the user's profile):</p>
  
  <pre><code>array(11) { ["wp_user_level"]=&gt; array(1) { [0]=&gt; string(1) "0" } ["show_admin_bar_front"]=&gt; array(1) { [0]=&gt; string(4) "true" } ["wp_capabilities"]=&gt; array(1) { [0]=&gt; string(32) "a:1:{s:10:"subscriber";s:1:"1";}" } ["use_ssl"]=&gt; array(1) { [0]=&gt; string(1) "0" } ["admin_color"]=&gt; array(1) { [0]=&gt; string(5) "fresh" } ["comment_shortcuts"]=&gt; array(1) { [0]=&gt; string(5) "false" } ["rich_editing"]=&gt; array(1) { [0]=&gt; string(4) "true" } ["description"]=&gt; array(1) { [0]=&gt; string(0) "" } ["nickname"]=&gt; array(1) { [0]=&gt; string(7) "emerson" } ["last_name"]=&gt; array(1) { [0]=&gt; string(0) "" } ["first_name"]=&gt; array(1) { [0]=&gt; string(0) "" } }
  </code></pre>