正在从外部链接更新用户元数据,用户未登录

时间:2019-04-28 作者:Kamran Asgari

我的登录过程如下所示:

1- user put email in the form

2- a link sent to email for setting password

3- user click on the link and redirect to website with code like this: https://www.example.com/my-account/?action=rp&key=oH02AnKdf3xGAU9TvAVew&login=email@example.com

现在在这个新表单中,我试图捕获密码并将其放入元数据表中;但是I can;t detect which user ID is logged in 访问网站。

在更改注册流程之前,我的注册代码是:

add_action( \'user_register\', \'myplugin_registration_save\', 10, 1 );
function myplugin_registration_save( $user_id ) {
        update_user_meta($user_id, \'user_pass2\', (string) $_POST[\'pass2\']);

}
为了更新密码,我使用了这个钩子:

add_action( \'profile_update\', \'my_profile_update\' );
但它们都是在用户实际登录并发布一些数据时使用的。

1 个回复
SO网友:butlerblog

我不完全清楚您想做什么,但似乎您想通过查询字符串传递用户的电子邮件地址,并由此确定用户。您可以从电子邮件值中获取用于写入用户元值的用户ID。使用该功能get_user_by() 通过用户的电子邮件检索用户对象。

$email = ( isset( $_GET[\'login\'] ) ) ? $_GET[\'login\'] : false;

$user = get_user_by( \'email\', $email );

if ( $user ) {
    update_user_meta( $user->ID, \'meta_key_to_save\', $value );
}