最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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 );
}
发布评论

评论列表(0)

  1. 暂无评论