简体   繁体   English

wordpress新注册用户后获取用户元数据

[英]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 来获取用户的信息。但不幸的是我无法访问用户元数据。例如 first_name,last_name 等

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?我从 $user_ID 收到新注册用户的 ID,但无法获取 $firstname 中的值。如何在注册新用户后获取用户元记录? 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: 这意味着, first_name是一个数组,你应该访问数组第一个元素first_name得到它:

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.但是firstNamelastName肯定是可用的。

You need to use the $userdata parameter, and for that you need to provide and add some parameters to your functions:您需要使用$userdata参数,为此您需要为您的函数提供并添加一些参数:

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.当这个钩子触发时,用户元数据还不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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