-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp-cron-auth.php
More file actions
25 lines (21 loc) · 854 Bytes
/
wp-cron-auth.php
File metadata and controls
25 lines (21 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
/**
* Plugin Name: WP-CRON Basic Auth
* Plugin URI: https://github.com/Briteweb/wp-cron-auth
* Description: Enable CRON behind basic auth.
* Version: 0.1.1
* Author: Briteweb
* Author URI: https://briteweb.com
* License: MIT License
*/
$shouldAddAuthentication = defined('WP_CRON_HTTP_BASIC_USERNAME') && defined('WP_CRON_HTTP_BASIC_PASSWORD');
/**
* Enable CRON behind HTTP Auth.
*/
if (function_exists('add_filter') && $shouldAddAuthentication) {
add_filter('cron_request', function ($request) {
$headers = ['Authorization' => sprintf('Basic %s', base64_encode(WP_CRON_HTTP_BASIC_USERNAME.':'.WP_CRON_HTTP_BASIC_USERNAME))];
$request['args']['headers'] = isset($request['args']['headers']) ? array_merge($request['args']['headers'], $headers) : $headers;
return $request;
});
}