WordPress cron not executing scheduled events

Large group of seated people in a dark room.
Imagine if no one attended a schedule event.

I recently tried to schedule an event to be executed twice daily in WordPress MU 3.5 via the wp_schedule_event function, but for some reason the event never fired.

I confirmed that the event was indeed scheduled properly, but when reviewing the timestamp of the event via wp_next_scheduled, it continued to return the timestamp of when I first scheduled it, indicating that it never executed.

After some testing and with the help of the Cron View plugin, which shows you a complete schedule of all cron jobs, I’ve come to realize that not even core WordPress events were being executed, pointing to a more global problem.

The most import information I gathered from this plugin was that all core WordPress events stopped firing on the same day, which means something affected it right around that time.

Eventually I remembered that I protected the WordPress installation with an Apache basic auth the day before. It prevented the WordPress cron from running, because it didn’t have the proper credentials to proceed.

A simple fix for this was to exclude the WordPress cron from needing authentication, which can be accomplished with the following few lines in your virtual host or htaccess file:

<FilesMatch "(wp-cron\.php)$">
    Allow from all
</FilesMatch>

Since this WordPress installation is only running in a staging environment, that piece of code was sufficient, but if this is your production environment, take a look at other possible file exclusions.

Last but not least, even though my cron was admin specific, placing the action within the admin_init hook didn’t not work, so keep in mind that it must used within init.

Featured image by Headway.


Comments (4)

Previously posted in WordPress and transferred to Ghost.

Miles
August 24, 2013 at 7:48 pm

This is simpler:
<Files wp-cron.php>
order deny,allow
deny from all
</Files>

AliMH
October 22, 2014 at 7:11 am

Hey mate, i have same problem, but with nginx config. when i changed my site server(dedicated server) some schedules works fine, others works more than asked, some others stop working! i really don’t know whats cause this!

Ryan Sechrest
October 22, 2014 at 9:10 am

So, everything was working fine until you changed servers? Is that the only thing you changed or did you update/install any plugins or themes? Maybe try the plugin I mentioned above to look at the cron jobs and note down which ones are and aren’t firing. Also, are you using basic authentication?

ujwal dhakal
February 16, 2015 at 10:57 am

i do facing the same issue they are already in queue in the time stamp i added your code not working bro