Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmt/f7cdebcb08ea324953c0204ebe2c2603 to your computer and use it in GitHub Desktop.
Save fmt/f7cdebcb08ea324953c0204ebe2c2603 to your computer and use it in GitHub Desktop.
WP Cron with HTTP Basic Authentication
<?php
if(defined('WP_CRON_CUSTOM_HTTP_BASIC_USERNAME') && defined('WP_CRON_CUSTOM_HTTP_BASIC_PASSWORD')) {
function http_basic_cron_request($cron_request) {
$headers = array('Authorization' => sprintf('Basic %s', base64_encode(WP_CRON_CUSTOM_HTTP_BASIC_USERNAME . ':' . WP_CRON_CUSTOM_HTTP_BASIC_PASSWORD)));
$cron_request['args']['headers'] = isset($cron_request['args']['headers']) ? array_merge($cron_request['args']['headers'], $headers) : $headers;
return $cron_request;
}
add_filter('cron_request', 'http_basic_cron_request');
}
@fmt
Copy link
Author

fmt commented Oct 5, 2018

This file should be in mu-plugins and this php in wp-config.php:

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');
}

(via http://nickohrn.com/2014/07/quick-tip-wp-cron-http-basic-protected-site/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment