Update custom field in User by email

Viewed 26

I have added a custom field for Users. The value is set with update_user_meta( $user_id, 'wwp_aanwezigheid', $_POST['wwp_aanwezigheid'] ); It works fine. I made it visible in the Users Table.

Idealy i would like to have the following setup: I send a mail to a (or all) user(s). That mail should have a YES and a NO button in the body. If they click on YES, the custom field wwp_aanwezigheid should be changed to "Aanwezig" If they click on NO, the custom field wwp_aanwezigheid should be changed to "Absent"

How can i update custom user fields by mail. Is it even possible? Do i compromize the security ?

Kind regards, Marco

1 Answers

I don't see how you could do this directly from email. You have to get them on the website and do the magic there.

Send email like you normally would and create two links with arguments like:

website.com/landing?user_id=12&wwp_aanwezigheid=true
website.com/landing?user_id=12&wwp_aanwezigheid=false

Create a function in function.php that reads URL arguments and use function: https://developer.wordpress.org/reference/functions/get_query_var/

After that just update the value

update_user_meta( $user_id, 'wwp_aanwezigheid', $wwp_aanwezigheid );

For security purposes encrypt their ID!

Related