Hooking WP-Cron into a task scheduling service

Before you start

  • Your intention is to enable configure WPO365's capability to synchronize users from Azure AD to WordPress.
  • You have installed the WPO365 | SYNC or WPO365 | INTRANET bundle (plus the WPO365 | LOGIN plugin that provides the basic functionality needed for either bundle to operate as expected).
  • You completed the steps in this article https://docs.wpo365.com/article/57-synchronize-users-from-azure-ad-to-wordpress and successfully configured WPO365's capability to synchronize users from Azure AD to WordPress.
  • You are an Administrator for your WordPress website and have access to your website's files e.g. through a file browser or FTP.
  • You have made sure that you have added wp-cron.php to the list of Pages freed from authentication on the plugin's Single Sign-on configuration page.

WP-Cron does not run continuously

The following text is based on this article https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/ found in the WordPress developer plugin handbook.

WP-Cron does not run continuously, which can be an issue if there are critical tasks that must run on time.

User synchronization is a critical task that must run on time because after the first batch of users is processed, the next batch is retrieved using a link that is only valid for short amount of time. If this link expires, user synchronization cannot continue.

There is an easy solution for this. Simply set up [...] a tool to make a web request to the wp-cron.php file [...] that runs on the intervals you desire (or at the specific time needed).

Task scheduling services

There are many different options you can choose from that can make a web request and that you can schedule. Two solutions (for Windows and for MacOS / Linux) presented in this article. Alternatively, you can schedule an Azure Function App to executes the following PowerShell command every minute.

Invoke-WebRequest <a href="http://YOUR_SITE_URL/wp-cron.php">https://YOUR_SITE_URL/wp-cron.php</a>

And last but not least you can purchase a PRO plan from UptimeRobot and configure it to call https://YOUR_SITE_URL/wp-cron.php every

Disable WP-Cron

WordPress will continue to run WP-Cron on each page load. This is no longer necessary and will contribute to extra resource usage on your server. WP-Cron can be disabled in the wp-config.php file. Open the file for editing and add the following line:

define('DISABLE_WP_CRON', true);
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us