Skip to content

"New direct message" notification email - configuring cron-jobs

Understand when Listivo sends its "New Direct Message" email, and add an external cron job so those emails go out within five minutes instead of waiting for the next visitor to trigger WP-Cron.

3 minute read

In this article, you will learn how Listivo's "New Direct Message" email notification works. It is a little different than other email notifications Listivo sends, because we developed some additional functions to make it more friendly for your visitors.

1. Two scenarios when the notification email is sent

  • If the receiver is not active on your website, the "New Direct Message" notification email is sent just after sending him a private message.
  • If the receiver is active, or was active in the last 5 minutes and hasn't seen the message, your website automatically uses the WP-Cron system to send the email. Listivo wants to send emails only when needed, so only when the user is not currently chatting. Imagine this notification being sent every time an active user receives a private message - it would be very annoying, and Listivo wants to avoid that.

2. How does it work by default?

By default Listivo uses the WP-Cron system to send this email. WP-Cron does not run constantly; it is only triggered on page load. Someone will need to visit your website to trigger the sending function. In WordPress it works the same way with, for example, scheduling posts (learn more here about the WP-Cron system).

3. How to be sure notifications are sent within 5 minutes

  1. 1 Create a free cron-job.org account

    Sign up at https://cron-job.org.

  2. 2 Start a new cronjob

    Click the CREATE CRONJOB button.

  3. 3 Add a title

    Any name that tells you what the job does.

  4. 4 Fill in the URL field

    Change the example http://domain.com/wp-cron.php to your own link - please make sure you enter your domain and that it has the right protocol (http or https). Make sure the link ends with /wp-cron.php, as in the screenshot.

    The cron-job.org cronjob editor: green arrows point at the Title field, filled in as "Listivo WP Cron Job", and at the URL field containing http://domain.com/wp-cron.php. Enable job is on and the schedule is set to every 1 minute.
  5. 5 Set the execution schedule

    Choose Every 1 Minute.

  6. 6 Click Create

Done. Cron-job.org will now, every one minute, force WordPress to check your website's "Cron Events". The "New Direct Message" notification email will be sent within 5 minutes to users who are active and are currently not chatting. Users who are offline get emails immediately.

4. Important information

Watch out for an email address conflict when testing
If you are testing the "New Direct Message" notification email, check that there is no "email address conflict". On some servers, when the primary WordPress email is the same as the address of the user you send the private message to, that user will not receive the email - it is blocked by the hosting or by the mailbox.
WordPress admin sidebar with green arrows pointing from Settings to the General item of its submenu, which also lists Writing, Reading, Discussion, Media, Permalinks, Privacy and Cron Schedules.
The WordPress Settings > General page with a green arrow pointing at the Administration Email Address field, whose value is blurred out.

5. Optional: stop WP-Cron running on every page load

You may consider adding this line to your /wp-config.php:

wp-config.php
define('DISABLE_WP_CRON', true);

It will disable running wp-cron every time someone accesses the site. It will then be executed only via cron-job.org, which you set up in point 3.

Ask the people who build Listivo

We answer by email from support@tangiblewp.com. With Premium Support, we also fix your site when something breaks.

Was this guide helpful?