You can solve it like this:
-
use wp_schedule_event to check if any user needs to get the mail
-
if yes, send the mail containing a link like
yoursite.com/?user_id=99&myaction=yes&mytoken=sometokenforsecurity
Save that token to the user´s user_meta
add_user_meta( $user_id, 'mytoken', $token, true )
In your case you obviously need a second link with action=no or whatever you want to call it
-
to catch that link you can use “template_redirect” like this:
add_action( 'template_redirect', 'my_callback' ); function my_callback() { // check if variables are sent if ( ! $user_id = filter_input( INPUT_GET, 'user_id', FILTER_VALIDATE_INT) ) return; if ( ! $action = filter_input( INPUT_GET, 'myaction' ) ) return; if ( ! $token = filter_input( INPUT_GET, 'mytoken' ) ) return; // check if token is valid $saved_token = get_user_meta( $user_id, 'mytoken', true ); if (!empty($saved_token) && $saved_token == $token) { // do the action // delete the token delete_user_meta($user_id, 'mytoken'); } // redirect the user to a confirmation page so he knows it worked or did not wp_redirect( get_home_url().'/my-confirmation-page'); }
Hope that helps!