0

Quick setup/info:

A user can login to my site and is presented with a form to complete. The form contains a Category drop down, and then 5 possible text fields with a Task Name and a Completion Date within that category. When the user makes changes and saves, the data is placed onto their profile - from the Wordpress Edit User screen I can see the Category, Task Names and Completion Dates.

Request/Help:

I would like to run a process daily that looks through every user profile and, for a user with a completion date 1 week away, sends that an email w/ the task name.

I also want to embed an image and text, including links, in the email based on the Category Name.

Any help or guidance is much appreciated, point me in the direction of how something like this would be handled and I'll start researching!!

Thank you!!

1 Answer 1

0

You can go about it this way, explanation in pseudo code and in the comments.

Create a function like the following in your functions.php file:

/**
 * This function collects the tasks that are due in a week and sends a reminder
 **/
function check_user_tasks_week_before() {
 // query which Completion Dates are in a week
 // loop through the results (if any)
 // and send every user in the result (or every task that is almost due) the email:
  // Send a mail:
  wp_mail( '[email protected]', 
   'Your task should be completed in a week', 
   'Hey, the deadline for your task blablabla is due in a week, get going or else!');
}

(For info about how to attach an image see this page at the WordPress codex.)

To schedule the task with wp_cron, so it runs every day, create a function like this in the file functions.php:

// If the task does not exist yet, it is created here:
if ( ! wp_next_scheduled( 'my_task_hook' ) ) {
  // you can specify what time() it should run (it is a unix timestamp)
  // in your case 'daily' would be a good choice:
  wp_schedule_event( time(), 'daily', 'my_task_hook' );
}

add_action( 'my_task_hook', 'check_user_tasks_week_before' );
2
  • Awesome feedback, thank you Tobias! Time to start researching and testing. Much appreciated!
    – Justin
    Nov 9, 2015 at 2:34
  • One word of advice: first build the 'check_user_tasks_week_before' function and test it - before you make it a cron task! If you find my answer sufficient, can you accept my answer? Good luck with your project! Nov 9, 2015 at 2:45

Your Answer

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

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