Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to access the $user->first_name property from a function triggered by the register_user action hook but it's not there:

function do_stuff($user_id) {

$new_user = get_userdata($user_id);

$first_name1 = $new_user->user_firstname;
$last_name1 = $new_user->user_lastname;
    echo "<" . $first_name1 . $last_name1 . ">";
    //returns: <>

$first_name2 = $new_user-first_name;
$last_name2 = $new_user->last_name;
    echo "<" . $first_name2 . $last_name2 . ">";
    //returns: <>

}
add_action("register_user", "do_stuff");

UPDATE:

I tried this:

$user_meta = get_user_meta( $new_user->ID );
var_dump($user_meta);

and I got this (last_name and first_name are empty even though they're defined in the user's profile):

array(11) { ["wp_user_level"]=> array(1) { [0]=> string(1) "0" } ["show_admin_bar_front"]=> array(1) { [0]=> string(4) "true" } ["wp_capabilities"]=> array(1) { [0]=> string(32) "a:1:{s:10:"subscriber";s:1:"1";}" } ["use_ssl"]=> array(1) { [0]=> string(1) "0" } ["admin_color"]=> array(1) { [0]=> string(5) "fresh" } ["comment_shortcuts"]=> array(1) { [0]=> string(5) "false" } ["rich_editing"]=> array(1) { [0]=> string(4) "true" } ["description"]=> array(1) { [0]=> string(0) "" } ["nickname"]=> array(1) { [0]=> string(7) "emerson" } ["last_name"]=> array(1) { [0]=> string(0) "" } ["first_name"]=> array(1) { [0]=> string(0) "" } }
share|improve this question

1 Answer 1

I think some user stuff changed in 3.2 and perhaps user meta works a bit differently now...

function do_stuff( $user_id ) {
    $first_name = get_user_meta( $user_id, 'first_name', true );
    $last_name = get_user_meta( $user_id, 'last_name', true );
    echo $first_name . $last_name;
}
add_action( 'user_register', 'do_stuff' );
share|improve this answer
    
I also get nothing from $first_name = get_user_meta( $user_id, 'first_name', true ); I've had all of these work in the past so I'm totally confused. –  SDP Aug 17 '12 at 14:39
    
@Emerson - are you sure you're getting nothing? outputting something within non-encoded angle brackets <> will hide it from view in a browser. tested and working for me in TwentyTen theme. –  Milo Aug 17 '12 at 15:02
    
@Emerson - also verify you are using the correct action, it's user_register not register_user as in your code example. –  Milo Aug 17 '12 at 15:06
    
Thanks for clarifying. That was a typo (I'm using user_register. –  SDP Aug 17 '12 at 15:40
    
I updated the question with the output of get_user_meta(). (Thanks for your help!) –  SDP Aug 17 '12 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.