PluginProbe
WP Cron HTTP Auth / 3.4
WP Cron HTTP Auth v3.4
3.6 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 All 28 releases
wp-cron-http-auth / wp-cron-http-auth.php

wp-cron-http-auth.php in WP Cron HTTP Auth 3.4, at wp-cron-http-auth.php

371 lines 13.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Cron HTTP Auth
4 Plugin URI: https://perishablepress.com/wp-cron-http-auth/
5 Description: Enable WP Cron on sites using HTTP Authentication
6 Tags: wp cron, cron, http auth, http, auth
7 Author: Jeff Starr
8 Author URI: https://plugin-planet.com/
9 Donate link: https://monzillamedia.com/donate.html
10 Contributors: specialk
11 Requires at least: 4.7
12 Tested up to: 7.0
13 Stable tag: 3.4
14 Version: 3.4
15 Requires PHP: 5.6.20
16 Text Domain: wp-cron-http-auth
17 Domain Path: /languages
18 License: GPL v2 or later
19
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License
22 as published by the Free Software Foundation; either version
23 2 of the License, or (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 with this program. If not, visit: https://www.gnu.org/licenses/
32
33 Copyright 2018-2026 Monzilla Media. All rights reserved.
34
35 */
36
37 if (!defined('ABSPATH')) exit;
38
39 if (!class_exists('WPCron_HTTPAuth')) {
40
41 class WPCron_HTTPAuth {
42
43 function __construct() {
44
45 $this->constants();
46 $this->includes();
47
48 add_action('admin_menu', array($this, 'add_menu'));
49 add_action('admin_init', array($this, 'add_settings'));
50 add_action('admin_init', array($this, 'check_version'));
51 add_filter('plugin_action_links', array($this, 'action_links'), 10, 2);
52 add_filter('plugin_row_meta', array($this, 'plugin_links'), 10, 2);
53 add_filter('admin_footer_text', array($this, 'footer_text'), 10, 1);
54 add_action('init', array($this, 'load_i18n'));
55
56 add_filter('cron_request', array($this, 'wp_cron_http_auth'));
57 }
58
59 function constants() {
60
61 if (!defined('WPCRONHTTPAUTH_VERSION')) define('WPCRONHTTPAUTH_VERSION', '3.4');
62 if (!defined('WPCRONHTTPAUTH_REQUIRE')) define('WPCRONHTTPAUTH_REQUIRE', '4.7');
63 if (!defined('WPCRONHTTPAUTH_AUTHOR')) define('WPCRONHTTPAUTH_AUTHOR', 'Jeff Starr');
64 if (!defined('WPCRONHTTPAUTH_NAME')) define('WPCRONHTTPAUTH_NAME', 'WP Cron HTTP Auth');
65 if (!defined('WPCRONHTTPAUTH_HOME')) define('WPCRONHTTPAUTH_HOME', esc_url('https://perishablepress.com/wp-cron-http-auth/'));
66 if (!defined('WPCRONHTTPAUTH_URL')) define('WPCRONHTTPAUTH_URL', plugin_dir_url(__FILE__));
67 if (!defined('WPCRONHTTPAUTH_DIR')) define('WPCRONHTTPAUTH_DIR', plugin_dir_path(__FILE__));
68 if (!defined('WPCRONHTTPAUTH_FILE')) define('WPCRONHTTPAUTH_FILE', plugin_basename(__FILE__));
69 if (!defined('WPCRONHTTPAUTH_SLUG')) define('WPCRONHTTPAUTH_SLUG', basename(dirname(__FILE__)));
70
71 }
72
73 function includes() {
74
75 // require_once WPCRONHTTPAUTH_DIR .'testing-wp-cron.php';
76
77 }
78
79 function add_menu() {
80
81 $title_page = esc_html__('WP Cron HTTP Auth', 'wp-cron-http-auth');
82 $title_menu = esc_html__('WP Cron HTTP Auth', 'wp-cron-http-auth');
83
84 add_options_page($title_page, $title_menu, 'manage_options', 'wp-cron-http-auth', array($this, 'display_settings'));
85
86 }
87
88 function add_settings() { // wp-cron-http-auth
89
90 register_setting('wpcron_httpauth_options', 'wpcron_httpauth_options', array($this, 'validate_settings'));
91
92 add_settings_section('general', esc_html__('Plugin Usage', 'wp-cron-http-auth'), array($this, 'section_general'), 'wpcron_httpauth_options');
93
94 add_settings_field('auth_username', esc_html__('HTTP Auth Username', 'wp-cron-http-auth'), array($this, 'callback_text'), 'wpcron_httpauth_options', 'general', array('id' => 'auth_username', 'label' => esc_html__('HTTP Auth Username', 'wp-cron-http-auth')));
95 add_settings_field('auth_password', esc_html__('HTTP Auth Password', 'wp-cron-http-auth'), array($this, 'callback_text'), 'wpcron_httpauth_options', 'general', array('id' => 'auth_password', 'label' => esc_html__('HTTP Auth Password', 'wp-cron-http-auth')));
96 add_settings_field('rate_plugin', esc_html__('Rate Plugin', 'wp-cron-http-auth'), array($this, 'callback_rate'), 'wpcron_httpauth_options', 'general', array('id' => 'rate_plugin', 'label' => esc_html__('Show support with a 5-star rating&nbsp;&raquo;', 'wp-cron-http-auth')));
97 add_settings_field('show_support', esc_html__('Show Support', 'wp-cron-http-auth'), array($this, 'callback_support'), 'wpcron_httpauth_options', 'general', array('id' => 'show_support', 'label' => esc_html__('Show support with a small donation&nbsp;&raquo;', 'wp-cron-http-auth')));
98
99 }
100
101 function display_settings() {
102
103 ?>
104
105 <div class="wrap">
106 <h1><?php echo WPCRONHTTPAUTH_NAME; ?></h1>
107 <form method="post" action="options.php">
108
109 <?php settings_fields('wpcron_httpauth_options'); ?>
110 <?php do_settings_sections('wpcron_httpauth_options'); ?>
111 <?php submit_button(); ?>
112
113 </form>
114 </div>
115
116 <?php
117
118 }
119
120 function section_general() {
121
122 echo '<p>'. esc_html__('This plugin enables WP Cron on sites using HTTP Authentication. Enter your HTTP Auth credentials, save changes, and done.', 'wp-cron-http-auth') .'</p>';
123
124 }
125
126 function validate_settings($input) {
127
128 if (isset($input['auth_username'])) $input['auth_username'] = esc_attr($input['auth_username']);
129 else $input['auth_username'] = null;
130
131 if (isset($input['auth_password'])) $input['auth_password'] = esc_attr($input['auth_password']);
132 else $input['auth_password'] = null;
133
134 return $input;
135
136 }
137
138 function callback_text($args) {
139
140 $default = $this->options();
141
142 $options = get_option('wpcron_httpauth_options', $default);
143
144 $id = isset($args['id']) ? $args['id'] : '';
145 $label = isset($args['label']) ? $args['label'] : '';
146
147 $option = isset($options[$id]) ? $options[$id] : '';
148
149 $config_vars = $this->config_vars();
150
151 $auth_username = (isset($config_vars['auth_username']) && !empty($config_vars['auth_username'])) ? $config_vars['auth_username'] : null;
152 $auth_password = (isset($config_vars['auth_password']) && !empty($config_vars['auth_password'])) ? $config_vars['auth_password'] : null;
153
154 if ($id === 'auth_username') {
155
156 $type = 'text';
157 $option = (!empty($auth_username)) ? $auth_username : $option;
158 $read = (!empty($auth_username)) ? ' readonly' : '';
159 $desc = (!empty($auth_username)) ? 'Username set in wp-config.php' : '';
160
161 } else {
162
163 $type = 'password';
164 $option = (!empty($auth_password)) ? $auth_password : $option;
165 $read = (!empty($auth_password)) ? ' readonly' : '';
166 $desc = (!empty($auth_password)) ? 'Password set in wp-config.php' : '';
167
168 }
169
170 echo '<label><input name="wpcron_httpauth_options['. esc_attr($id) .']" type="'. esc_attr($type) .'" class="regular-text" value="'. esc_attr($option) .'"'. $read .'></label> ';
171 echo '<span class="input-desc" style="font-size:80%;color:#5C8D6A;">'. $desc .'</span>';
172
173 }
174
175 function callback_rate($args) {
176
177 $href = 'https://wordpress.org/support/plugin/'. WPCRONHTTPAUTH_SLUG .'/reviews/?rate=5#new-post';
178 $title = esc_attr__('Please give a 5-star rating! A huge THANK YOU for your support!', 'wp-cron-http-auth');
179 $text = isset($args['label']) ? $args['label'] : esc_html__('Show support with a 5-star rating&nbsp;&raquo;', 'wp-cron-http-auth');
180
181 echo '<a target="_blank" rel="noopener noreferrer" class="wp-cron-http-auth-rate-plugin" href="'. $href .'" title="'. $title .'">'. $text .'</a>';
182
183 }
184
185 function callback_support($args) {
186
187 $href = 'https://monzillamedia.com/donate.html';
188 $title = esc_attr__('Donate via PayPal, credit card, or cryptocurrency', 'wp-cron-http-auth');
189 $text = isset($args['label']) ? $args['label'] : esc_html__('Show support with a small donation&nbsp;&raquo;', 'wp-cron-http-auth');
190
191 echo '<a target="_blank" rel="noopener noreferrer" class="wp-cron-http-auth-show-support" href="'. $href .'" title="'. $title .'">'. $text .'</a>';
192
193 }
194
195 function options() {
196
197 $options = array(
198
199 'auth_username' => '',
200 'auth_password' => '',
201
202 );
203
204 return apply_filters('wpcron_httpauth_options', $options);
205
206 }
207
208 function action_links($links, $file) {
209
210 if ($file === WPCRONHTTPAUTH_FILE && current_user_can('manage_options')) {
211
212 $settings = '<a href="'. admin_url('options-general.php?page=wp-cron-http-auth') .'">'. esc_html__('Settings', 'wp-cron-http-auth') .'</a>';
213
214 array_unshift($links, $settings);
215
216 }
217
218 return $links;
219
220 }
221
222 function plugin_links($links, $file) {
223
224 if ($file === WPCRONHTTPAUTH_FILE) {
225
226 $home_href = 'https://perishablepress.com/wp-cron-http-auth/';
227 $home_title = esc_attr__('Plugin Homepage', 'wp-cron-http-auth');
228 $home_text = esc_html__('Homepage', 'wp-cron-http-auth');
229
230 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
231
232 $rate_href = 'https://wordpress.org/support/plugin/'. WPCRONHTTPAUTH_SLUG .'/reviews/?rate=5#new-post';
233 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'wp-cron-http-auth');
234 $rate_text = esc_html__('Rate this plugin', 'wp-cron-http-auth') .'&nbsp;&raquo;';
235
236 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
237
238 }
239
240 return $links;
241
242 }
243
244 function footer_text($text) {
245
246 $screen_id = $this->screen_id();
247
248 $ids = array('settings_page_wp-cron-http-auth');
249
250 if ($screen_id && apply_filters('wp_cron_http_auth_admin_footer_text', in_array($screen_id, $ids))) {
251
252 $text = __('Like this plugin? Give it a', 'wp-cron-http-auth');
253
254 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/wp-cron-http-auth/reviews/?rate=5#new-post">';
255
256 $text .= __('�
257 �
258 �
259 �
260 �
261 rating&nbsp;&raquo;', 'wp-cron-http-auth') .'</a>';
262
263 }
264
265 return $text;
266
267 }
268
269 function screen_id() {
270
271 if (!function_exists('get_current_screen')) require_once ABSPATH .'/wp-admin/includes/screen.php';
272
273 $screen = get_current_screen();
274
275 if ($screen && property_exists($screen, 'id')) return $screen->id;
276
277 return false;
278
279 }
280
281 function check_version() {
282
283 $wp_version = get_bloginfo('version');
284
285 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
286
287 if (version_compare($wp_version, WPCRONHTTPAUTH_REQUIRE, '<')) {
288
289 if (is_plugin_active(WPCRONHTTPAUTH_FILE)) {
290
291 deactivate_plugins(WPCRONHTTPAUTH_FILE);
292
293 $msg = '<strong>'. WPCRONHTTPAUTH_NAME .'</strong> '. esc_html__('requires WordPress ', 'wp-cron-http-auth') . WPCRONHTTPAUTH_REQUIRE;
294 $msg .= esc_html__(' or higher, and has been deactivated! ', 'wp-cron-http-auth');
295 $msg .= esc_html__('Please return to the', 'wp-cron-http-auth') .' <a href="'. admin_url() .'">';
296 $msg .= esc_html__('WP Admin Area', 'wp-cron-http-auth') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'wp-cron-http-auth');
297
298 wp_die($msg);
299
300 }
301
302 }
303
304 }
305
306 }
307
308 function wp_cron_http_auth($cron_request) {
309
310 $config_vars = $this->config_vars();
311
312 $auth_username = (isset($config_vars['auth_username']) && !empty($config_vars['auth_username'])) ? $config_vars['auth_username'] : null;
313 $auth_password = (isset($config_vars['auth_password']) && !empty($config_vars['auth_password'])) ? $config_vars['auth_password'] : null;
314
315 if (empty($auth_username) || empty($auth_password)) {
316
317 $options = get_option('wpcron_httpauth_options', $this->options());
318
319 $auth_username = (isset($options['auth_username']) && !empty($options['auth_username'])) ? $options['auth_username'] : null;
320 $auth_password = (isset($options['auth_password']) && !empty($options['auth_password'])) ? $options['auth_password'] : null;
321
322 }
323
324 if ($auth_username && $auth_password) {
325
326 $headers = array('Authorization' => sprintf('Basic %s', base64_encode($auth_username .':'. $auth_password)));
327
328 $cron_request['args']['headers'] = isset($cron_request['args']['headers']) ? array_merge($cron_request['args']['headers'], $headers) : $headers;
329
330 }
331
332 return $cron_request;
333
334 }
335
336 function config_vars() {
337
338 $auth_username = '';
339 $auth_password = '';
340
341 if (defined('WP_CRON_HTTP_AUTH_USERNAME') && !empty('WP_CRON_HTTP_AUTH_USERNAME')) $auth_username = WP_CRON_HTTP_AUTH_USERNAME;
342 if (defined('WP_CRON_HTTP_AUTH_PASSWORD') && !empty('WP_CRON_HTTP_AUTH_PASSWORD')) $auth_password = WP_CRON_HTTP_AUTH_PASSWORD;
343
344 return array('auth_username' => $auth_username, 'auth_password' => $auth_password);
345
346 }
347
348 function load_i18n() {
349
350 load_plugin_textdomain('wp-cron-http-auth', false, dirname(WPCRONHTTPAUTH_FILE) .'/languages/');
351
352 }
353
354 function __clone() {
355
356 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'wp-cron-http-auth'), WPCRONHTTPAUTH_VERSION);
357
358 }
359
360 function __wakeup() {
361
362 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'wp-cron-http-auth'), WPCRONHTTPAUTH_VERSION);
363
364 }
365
366 }
367
368 $WPCron_HTTPAuth = new WPCron_HTTPAuth();
369
370 }
371