我正在尝试从由触发的函数访问$user->first\\u name属性register_user
动作钩,但它不在那里:
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");
更新时间:
我试过这个:
$user_meta = get_user_meta( $new_user->ID );
var_dump($user_meta);
我得到了这个(last\\u name和first\\u name是空的,即使它们是在用户配置文件中定义的):
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) "" } }
SO网友:Milo
我认为3.2中的一些用户内容发生了变化,也许用户元现在的工作方式有所不同。。。
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\' );