I have built a sort of marketplace platform based on WordPress and I would like to build a few email-related functionalities to keep the platform easier to use and make it cleaner.

Examples of this are sending the user an email 30 days after they posted a listing and asking them whether it is still current (and giving the option to click a link to delete it if not) or offering a yes/no mechanism (i.e. I already have a mechanism that uses wp_mail() to let a user know that someone else is interested in their listing and send that user's details, so I'd like to add two links to that email that have WordPress send a confirmation or rejection notice to the user that triggered the original email).

I spend quite some time googling and didn't find any information on this.

For deleting posts it'd be pretty easy to put in a get_delete_post_link() to the email, but I'm not sure how to pass the $post_ID and how to have the thing be sent out 30 days later.

Are such things possible with just WordPress or would I need to add an email system to it in order to work?


1 Answer 1


You can solve it like this:

  1. use wp_schedule_event to check if any user needs to get the mail

  2. if yes, send the mail containing a link like


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

  1. 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) )
      if ( ! $action = filter_input( INPUT_GET, 'myaction' ) )
      if ( ! $token = filter_input( INPUT_GET, 'mytoken' ) )
      // 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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.