Today I ran into a situation where I needed the default WP Cron processing to work while a site was protected behind HTTP Basic authentication. If you’re not familiar with the way WP Cron works by default, it spawns an HTTP request to example.com/wp-cron.php
on page load (given a certain set of conditions) and allows that request to sit and process whatever jobs have been registered.
When HTTP Basic authentication is active on the site root, though, the request never gets through to wp-cron.php
because it gets intercepted by the web server and blocked (because the request isn’t authenticated). To get around that, add the following code into your wp-config.php file:
if(!defined('WP_CRON_CUSTOM_HTTP_BASIC_USERNAME')) {
define('WP_CRON_CUSTOM_HTTP_BASIC_USERNAME', 'YOUR_USERNAME_HERE');
}
if(!defined('WP_CRON_CUSTOM_HTTP_BASIC_PASSWORD')) {
define('WP_CRON_CUSTOM_HTTP_BASIC_PASSWORD', 'YOUR_PASSWORD_HERE');
}
Then, download this gist and put it inside of the mu-plugins
directory.
That’s it!
Great! Thanks a lot for the solution!
Works fine on latest version of WP – 4.4.2
Manuel – I’m so happy this worked for you!
This is a great workaround Nick. Thanks for sharing.
Great, you saving my life :-)
Pingback: WordPress Cronjob (wp-cron.php) trotz HTTP-Authentifizierung ausführen | kulturbanause® blog