简体   繁体   中英

Get user meta data after newly registration user in wordpress

I am using this function to get the information of User.But unfortunately i can't able to access the user meta data.Forexample first_name,last_name etc

function registerUserInSalesForce($user_ID)
{        
$firstname=get_user_meta($user_ID,'first_name',true);
update_option('update_meta',$firstname);

}
add_action( 'user_register', 'registerUserInSalesForce');

I am receiving newly register user's id from $user_ID but cannot able to get the value in $firstname.How can i get the user meta record after registering new user? Thanks for any Help!

From codex results example :

Array ( [first_name] => Array ( [0] => Tom ) [last_name] => Array ( [0] => Auger) [nickname] => Array ( [0] => tomauger ) [description] => etc.... )

That means, first_name is an array and you should access first element in array first_name to get it:

function registerUserInSalesForce($user_ID)
{        
$firstname=get_user_meta($user_ID,'first_name',true);
update_option('update_meta',$firstname[0]);
}
add_action( 'user_register', 'registerUserInSalesForce');

I'm not sure if this will be able to help, as it depends on which data do you need. But firstName and lastName are definitely available.

You need to use the $userdata parameter, and for that you need to provide and add some parameters to your functions:

function registerUserInSalesForce( $user_id, $userdata )
{        
    $firstname = $userdata['first_name'];
    //$firstname = $userdata['last_name'];
    update_option('update_meta', $firstname);
}
add_action( 'user_register', 'registerUserInSalesForce', 10, 2);

This information is part of the user's information, and it's not user meta. User meta doesn't exist yet when this hook triggers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM