Tag Archives: Basic Auth

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.