在 Wordpress 中访问有关用户注册的用户元数据 [英] Access User Meta Data on User Registration in Wordpress

查看:35
本文介绍了在 Wordpress 中访问有关用户注册的用户元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在 wordpress 网站上注册时,我试图执行一些功能.我为此创建了一个模块,它执行以下功能:

add_action('user_register', 'tml_new_user_registered');函数 tml_new_user_registered( $user_id ) {//wp_set_auth_cookie( $user_id, false, is_ssl() );//wp_redirect( admin_url( 'profile.php' ) );$user_info = get_userdata($user_id);$subscription_value = get_user_meta( $user_id, "subscribe_to_newsletter", TRUE);if($subscription_value == "是") {//include("Subscriber.Add.php");}echo "

: ";打印_r($user_info);print_r($subscription_value);echo "</pre>";出口;}

但似乎我无法访问任何用户元数据,因为在此阶段结束时没有存储任何元数据.

在 Wordpress 完成将元数据添加到相关表格的整个注册过程后,我知道如何执行函数吗?

我尝试使用这个:

add_filter('user_register','tml_new_user_registered',99);

但不幸的是没有运气.

提前致谢!

解决方案

我认为在触发此操作挂钩时用户元数据不可用.来自 Codex

"触发此操作时,并非所有用户元数据都已存储在数据库中.例如,昵称在数据库中,但 first_name 和 last_name 不在数据库中(截至 3.9.1).密码已加密触发此操作."

I am attempting to carry out a few functions when a user registers on a wordpress site. I have created a module for this which carries out the following function:

add_action( 'user_register', 'tml_new_user_registered' );

function tml_new_user_registered( $user_id ) {
    //wp_set_auth_cookie( $user_id, false, is_ssl() );
    //wp_redirect( admin_url( 'profile.php' ) );
    $user_info = get_userdata($user_id);
        $subscription_value = get_user_meta( $user_id, "subscribe_to_newsletter", TRUE);
    if($subscription_value == "Yes") {
        //include("Subscriber.Add.php");    
    }


    echo "<pre>: ";
    print_r($user_info);
    print_r($subscription_value);
    echo "</pre>";

    exit;
}

But it seems that i am not able to access any user meta data as at the end of this stage none of it is stored.

Any ideas how i execute a function once Wordpress has completed the whole registration process of adding meta data into the relevant tables too?

I attempted to use this:

add_filter('user_register ','tml_new_user_registered',99);

But with no luck unfortunately.

Thanks in advance!

解决方案

I don't think the user metadata is available at the point where this action hook is triggered. From the Codex

"Not all user meta data has been stored in the database when this action is triggered. For example, nickname is in the database but first_name and last_name are not (as of 3.9.1). The password has already been encrypted when this action is triggered."

这篇关于在 Wordpress 中访问有关用户注册的用户元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆