hooks - Updating user meta data from external link, user not logged in

My login process is exactly like this:1- user put email in the form2- a link sent to email for setting password3- user c

My login process is exactly like this:

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: /?action=rp&key=oH02AnKdf3xGAU9TvAVew&[email protected]

Now in this new form, I'm trying to capture the password and put it into the meta data table; but I can;t detect which user ID is logged in to the website.

My code was this for registration before I changed the registration process:

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']);

}

And for updating the password, I used this hook:

add_action( 'profile_update', 'my_profile_update' );

But they both used when the user actually logged in and post some data.

My login process is exactly like this:

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/my-account/?action=rp&key=oH02AnKdf3xGAU9TvAVew&[email protected]

Now in this new form, I'm trying to capture the password and put it into the meta data table; but I can;t detect which user ID is logged in to the website.

My code was this for registration before I changed the registration process:

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']);

}

And for updating the password, I used this hook:

add_action( 'profile_update', 'my_profile_update' );

But they both used when the user actually logged in and post some data.

Share Improve this question edited Apr 29, 2019 at 0:15 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Apr 28, 2019 at 19:29 zEn feeLozEn feeLo 2073 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I'm not entirely clear on what you're trying to do, but it seems you want to pass the user's email address via a query string and determine the user by that. You can get the user's ID for writing user meta values from the email value. Use the function get_user_by() to retrieve the user object by the user's email.

$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 );
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745542992a4632214.html

相关推荐

  • hooks - Updating user meta data from external link, user not logged in

    My login process is exactly like this:1- user put email in the form2- a link sent to email for setting password3- user c

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信