WordPress cron not executing scheduled events

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 crons, 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

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.

4 thoughts on “WordPress cron not executing scheduled events

  1. AliMH

    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!

    1. Ryan Sechrest Post author

      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?


Leave a Reply

Your email address will not be published.