How to set up run rule automatically to create reminders via CRON?

This article relative to the "Email Reminders" update 2.0 or newer

Why we need to run rules periodically?
We need to run specific rules periodically, for creation of new email reminders, because usually rules have some conditions based on days or times depending from TODAY date.
For example:

Sending Reminder email, 1 day before the event.
It means that, if today is "2021-12-01", we need to search for all contacts with check_in date: "2021-12-02" ( e.g. TODAY + 1 DAY). If check_in date field contain times (like 2021-12-02 10:01:00), then we need to use 2 conditions:

check_in > TODAY + 1 DAY ( e.g. 2021-12-02 00:00:00 )
check_in <= TODAY + 2 DAYS - 1 SECOND ( e.g. 2021-12-02 23:59:59 )

Follow-up email. 7 days after the event (TODAY - 7 DAYS):

check_in > TODAY - 7 DAYS
check_in <= TODAY - 8 DAYS + 1 SECOND

After 1.5 months (TODAY - 1 MONTH - 15 DAYS):

check_in > TODAY - 1 MONTH - 15 DAYS
check_in <= TODAY - 1 MONTH - 15 DAYS + 1 SECOND


CRON
Because each next day variable TODAY will have the new value, we need to run such rule(s) periodically each new day
(or during other period of time if you have the different time conditions ). Here CRON system of your website can help to us.

In pure WordPress system it works with pseudo-cron functionality. WordPress Cron is what many people refer to as a "pseudo-cron system". The difference is in how UNIX cron and WordPress Cron take action.

A typical UNIX cron system runs in this order:

  • A time tied to an action occurs.
  • Cron runs the action tied to that time.

With WordPress Cron, it works a little differently:

  • A visitor comes to any page on your WordPress website.
  • WordPress Cron checks each cron event to see whether the scheduled time has been passed.
  • If the scheduled time for that event was passed, then WordPress Cron executes any actions tied to that event.

The detail description about Linux style of CRON commands you can check here. Other example of other CRON commands for other periods of time you can find here.
But usually you can configure your cron script via your server administration panel, like ISP Manager or Cpanel, in easier way via menu and not the commands. Help info about configuration of CRON script in ISP Manager server administration panel you can check here or here (older versions). Help info about configuration of CRON script in Cpanel server administration panel you can check here or here. For more info, please contact support of your hosting. Hosting support should know exactly what server administration panel you are using at your server, and how to configure your CRON script. Note. We do not provide support of configuration CRON at your servers.
Check how to setup the Cron job or read more about Hooking WP-Cron Into the System Task Scheduler, if you are WordPress developer.

The command you want to use in CRON is

wget -qO- https://yourserver.com/wp-cron.php &> /dev/null

Instead of "yourserver.com" use your website DNS.
The reasonable time interval is between 5-15 minutes.
That is */5 * * * * or */15 * * * * for Cron interval setting.


Configuration of Email Reminders Plugin - Automate (CRON) settings.
Open Email Reminders > Rules plugin menu page. When you click on "Add New Rule" button in toolbar or if you click on "Edit" button of exist Rule, you will get screen with configuration of Rule.

Configure CRON rules

Configure CRON rules


Read more about configuration of Rules conditions here. Here we are interesting in "Automate - CRON" section for the Rules.

1. Automatic Rules running
You need to activate "Enable rule run" option and configure additional parameters:

Automate Cron - Rule Run

Automate Cron - Rule Run

  • "next time at" field - define when the rule will start during next time. Leave it empty, if you want to make execution immediately.
  • "recurrence interval" (days / hours / minutes or in seconds ) - define time interval when next time system must to execute this rule starting from "last checked contact id". Check more here.
  • "contacts to process per execution" - it's number of contacts to process by rules per iteration.

    For example, if you defined here value as 1000 contacts, and last checked contact id was 3000, so during current execution of Rule, system will process contacts from 3000 to 4000, then define last checked contact id as 4000, create some email-reminders, from this 1000 processed contacts, if they fit to Rules conditions. And after passed next "recurrence interval" system will start this iteration again from last checked contact id (in our example it's already 4000 ), and so on. Until system will not process all existing contacts.
    Why we don't process all contacts during one step?
    Imagine a situation, if you are having 1 000 000 contacts or more, so in this case, your server just can not process such a big amount of data during one time, and you will have a timeout error. That's why such an option for setting the number of contacts to process gives us great flexibility and scalability for a huge number of contacts to process. This is also useful in situations, where the execution was interrupted for some reason, and the next time you start with the remained contact lists.
  • "approximate time to send reminders:" - it's useful fields, to define when system has to send email-reminders and at what approximate time interval to send email reminders. For example, you can deactivate to NOT send email reminders at Saturday and Sundays, and you can define to send email-reminders only at morning from 10:00 to 12:00 for specific Rule.
    Please note, you can create other Rule with other conditions (for example for visitors from other countries (based on contact fields conditions) to send email-reminders at other time interval, for example from 18:00 to 20:00. It's useful for visitors in other time zone. Please note, you are defined the times based on your server time-zone.

2. Automatic Rules resetting
Activate "Enable resetting" option. This option define "last checked contact id" to initial value (usually it's 0).

Automate Cron - Rule Reset

Automate Cron - Rule Reset

Why do we need to make such resetting of "last checked contact id" ?
Imagine a situation, when we have 14700 contacts. System during TODAY date executed this rule with specific conditions:

check_in > TODAY + 1 DAY ( e.g. 2021-12-02 00:00:00 )
check_in <= TODAY + 2 DAYS - 1 SECOND ( e.g. 2021-12-02 23:59:59 )

System creats several email reminders for sending emails, 1 day before the event. This rule will have status FINISHED at the Rules listing page (check here ).

But what will be during tomorrow with such a rule?
Nothing. Because the status of this rule is finished and we have processed all our contacts. Probably during tomorrow, we need to start this rule again from the beginning of the contact list. In other words we need to set contact ID to 0 for such a rule, and check all our contacts again about creation of new email reminders that will be sent for 1 day before the event (during tomorrow, and etc...). And that is why you need to reset the existed rule by setting "last checked contact id" to 0 (or some other value, if you do not need to start from first contact).
So during tomorrow system will reset contact ID to 0 and will start processing our contacts from beginning. It means that during each next day we will process all contacts and create relative correct email reminders for specific dates.

Now back to our settings. We can define such parameters:

  • "next time at" field - define when next time this rule will set "last checked contact id" to 0 (or some other value). Usually you can define here some date with time, that is early than time of "next time at" field in "Enable rule run" section.
  • "recurrence interval" (days / hours / minutes or in seconds ) - define time interval when next time system have to set "last checked contact id" to 0 (or some other value)
  • "last checked contact id" usually it can be 0, but it's also can be different value, if you do not need to start from first contact (check more here).

3. Automatic sending "email reminders"
Activate automatic sending "email reminders" option and define the sending time intervals for group of such email reminders.

CRON settings


Open "Email Reminders" > Settings > Automate (CRON) menu page and set checked this option " Enable CRON to send reminders" to send email reminders automatically. Also you can define the time intervals, when CRON system will check for sending email reminders and define Number of reminders to send option.

4. Use Server CRON
Define using Server CRON or leave using default WordPress pseudo CRON.
At the "Email Reminders" > Settings > Automate (CRON) menu page you can activate "Enable Server Scheduler" option to use Server CRON instead of WordPress pseudo cron functionality. When enabled WordPress will not spawn Cron anymore. You have to set the Cron on your server.