PluginProbe
Captcha Code / trunk
Captcha Code vtrunk
trunk 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.31 3.32
captcha-code-authentication / wpCaptcha.php

wpCaptcha.php in Captcha Code trunk, at wpCaptcha.php

1,375 lines 58.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Captcha Code
4 Description: Adds captcha to front-end forms.
5 Version: 3.32
6 Author: WebFactory Ltd
7 Author URI: https://www.webfactoryltd.com/
8 License: GPL2
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2, as
12 published by the Free Software Foundation.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 // include only file
25 if (!defined('ABSPATH')) {
26 wp_die(esc_html__('Do not open this file directly.', 'captcha-code-authentication'));
27 }
28
29 define('WP_CAPTCHA_CODE_URL', plugin_dir_url(__FILE__));
30 define('WP_CAPTCHA_CODE_DIR', dirname(__FILE__));
31 define('WP_CAPTCHA_CODE_OPTIONS', 'wp_captcha_code_options');
32 define('WP_CAPTCHA_CODE_POINTERS_KEY', 'wp_captcha_code_pointers');
33
34 require_once WP_CAPTCHA_CODE_DIR . '/wf-flyout/wf-flyout.php';
35
36 class WP_Captcha_Code
37 {
38 static $version;
39 static $options;
40
41 static function init()
42 {
43 self::$version = self::get_plugin_version();
44 $options = self::load_options();
45
46 if (!session_id()) {
47 @session_start();
48 }
49
50 if (is_admin()) {
51 new wf_flyout(__FILE__);
52
53 add_action('admin_menu', array(__CLASS__, 'admin_menu'));
54 add_action('wp_before_admin_bar_render', array(__CLASS__, 'admin_bar'));
55 add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts'));
56 add_action('admin_action_wp_captcha_code_install_wp301', array(__CLASS__, 'install_wp301'));
57 add_filter('admin_footer_text', array(__CLASS__, 'admin_footer_text'));
58 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(__CLASS__, 'plugin_action_links'));
59 add_action('wp_ajax_wp_captcha_code_dismiss_pointers', array(__CLASS__, 'dismiss_pointers'));
60 } else {
61 if ($options['enabled'] == 'yes' && $options['show_login'] == 'yes') {
62 add_action('login_form', array(__CLASS__, 'captcha_for_login'));
63 add_filter('login_errors', array(__CLASS__, 'captcha_login_errors'));
64 add_filter('login_redirect', array(__CLASS__, 'captcha_login_redirect'), 10, 3);
65 }
66
67 if ($options['enabled'] == 'yes' && $options['show_comments'] == 'yes') {
68 add_action('comment_form_after_fields', array(__CLASS__, 'captcha_comment_form'), 1);
69 add_action('comment_form_logged_in_after', array(__CLASS__, 'captcha_comment_form'), 1);
70 add_filter('preprocess_comment', array(__CLASS__, 'captcha_comment_post'));
71 }
72
73 if ($options['enabled'] == 'yes' && $options['show_registration'] == 'yes') {
74 add_action('register_form', array(__CLASS__, 'wp_captcha_register'));
75 add_action('register_post', array(__CLASS__, 'captcha_register_post'), 10, 3);
76 add_action('signup_extra_fields', array(__CLASS__, 'wp_captcha_register'));
77 add_filter('wpmu_validate_user_signup', array(__CLASS__, 'captcha_register_validate'));
78 }
79
80 if ($options['enabled'] == 'yes' && $options['show_lost_password'] == 'yes') {
81 add_action('lostpassword_form', array(__CLASS__, 'captcha_lostpassword'));
82 add_action('lostpassword_post', array(__CLASS__, 'captcha_lostpassword_post'), 10, 3);
83 }
84 }
85 } // init
86
87
88 // add settings link to plugins page
89 static function plugin_action_links($links)
90 {
91 $settings_link = '<a href="' . admin_url('options-general.php?page=captcha-code-authentication') . '" title="Configure Captcha">Configure Captcha</a>';
92 $pro_link = '<a href="' . admin_url('options-general.php?page=captcha-code-authentication#get-pro') . '" title="Get PRO"><b>Get PRO</b></a>';
93
94 array_unshift($links, $settings_link);
95 array_unshift($links, $pro_link);
96
97 return $links;
98 } // plugin_action_links
99
100 static function admin_enqueue_scripts($hook)
101 {
102 if ('settings_page_captcha-code-authentication' == $hook) {
103 wp_enqueue_style('wp-jquery-ui-dialog');
104 wp_enqueue_style('wp-captcha-code-admin', WP_CAPTCHA_CODE_URL . 'css/wp-captcha-code.css', array(), self::$version);
105
106 wp_enqueue_script('jquery-ui-core');
107 wp_enqueue_script('jquery-ui-position');
108 wp_enqueue_script('jquery-effects-core');
109 wp_enqueue_script('jquery-effects-blind');
110 wp_enqueue_script('jquery-ui-dialog');
111
112 $js_localize = array(
113 'wp301_install_url' => add_query_arg(array('action' => 'wp_captcha_code_install_wp301', '_wpnonce' => wp_create_nonce('install_wp301'), 'rnd' => wp_rand()), admin_url('admin.php'))
114 );
115
116 wp_enqueue_script('wp-captcha-code-admin', WP_CAPTCHA_CODE_URL . 'js/wp-captcha-code.js', array('jquery'), self::$version, true);
117 wp_localize_script('wp-captcha-code-admin', 'wp_captcha_code_vars', $js_localize);
118 } else {
119 $pointers = get_option(WP_CAPTCHA_CODE_POINTERS_KEY);
120
121 if ($pointers) {
122 $pointers['dismiss_pointer_nonce'] = wp_create_nonce('wp_captcha_code_dismiss_pointer');
123 wp_enqueue_script('wp-pointer');
124 wp_enqueue_style('wp-pointer');
125 wp_localize_script('wp-pointer', 'wp_captcha_code_pointers', $pointers);
126 }
127
128 if ($pointers) {
129 wp_enqueue_script('wp-captcha-code-pointers', WP_CAPTCHA_CODE_URL . 'js/wp-captcha-code-pointers.js', array('jquery'), self::$version, true);
130 }
131 }
132 } // admin_enqueue_scripts
133
134 static function reset_pointers()
135 {
136 $pointers = array();
137 $pointers['welcome'] = array('target' => '#menu-settings', 'edge' => 'left', 'align' => 'right', 'content' => 'Thank you for installing the <b style="font-weight: 800; font-variant: small-caps;">Captcha</b> plugin! Please open <a href="' . admin_url('options-general.php?page=captcha-code-authentication') . '">Settings -> Captcha</a> to set up your captcha and website protection settings.');
138
139 update_option(WP_CAPTCHA_CODE_POINTERS_KEY, $pointers);
140 } // reset_pointers
141
142 static function dismiss_pointers()
143 {
144 check_ajax_referer('wp_captcha_code_dismiss_pointer');
145
146 if (!current_user_can('manage_options')) {
147 wp_send_json_error(__('You are not allowed to run this action.', 'captcha-code-authentication'));
148 }
149
150 delete_option(WP_CAPTCHA_CODE_POINTERS_KEY);
151 }
152
153 static function is_plugin_page()
154 {
155 $current_screen = get_current_screen();
156
157 if ($current_screen->id == 'settings_page_captcha-code-authentication') {
158 return true;
159 } else {
160 return false;
161 }
162 } // is_plugin_page
163
164 static function admin_footer_text($text)
165 {
166 if (!self::is_plugin_page()) {
167 return $text;
168 }
169
170 $text = '<i class="wp-captcha-code-footer">Captcha Code v' . self::$version . ' <a href="' . self::generate_web_link('admin_footer') . '" title="Visit WP Captcha page for more info" target="_blank">WebFactory Ltd</a>. Please <a target="_blank" href="https://wordpress.org/support/plugin/captcha-code-authentication/reviews/#new-post" title="Rate the plugin">rate the plugin <span>�
171 �
172 �
173 �
174 �
175 </span></a> to help us spread the word. Thank you 🙌 from the WebFactory team!</i>';
176
177 return $text;
178 } // admin_footer_text
179
180 static function generate_web_link($placement = '', $page = '/', $params = array(), $anchor = '')
181 {
182 $base_url = 'https://getwpcaptcha.com';
183
184 if ('/' != $page) {
185 $page = '/' . trim($page, '/') . '/';
186 }
187 if ($page == '//') {
188 $page = '/';
189 }
190
191 $parts = array_merge(array('utm_source' => 'captcha-code-authentication', 'utm_content' => $placement), $params);
192
193 if (!empty($anchor)) {
194 $anchor = '#' . trim($anchor, '#');
195 }
196
197 $out = $base_url . $page . '?' . http_build_query($parts, '', '&amp;') . $anchor;
198
199 return $out;
200 } // generate_web_link
201
202 static function load_options()
203 {
204 $options = get_option(WP_CAPTCHA_CODE_OPTIONS, array());
205 $change = false;
206
207 if (!isset($options['meta'])) {
208 $options['meta'] = array('first_version' => self::$version, 'first_install' => current_time('timestamp', true), 'pointer' => true);
209 self::reset_pointers();
210 $change = true;
211 } else if(!array_key_exists('pointer', $options['meta'])){
212 $options['meta']['pointer'] = true;
213 self::reset_pointers();
214 $change = true;
215 }
216
217 if (!isset($options['dismissed_notices'])) {
218 $options['dismissed_notices'] = array();
219 $change = true;
220 }
221
222 if (!isset($options['options'])) {
223 $options['options'] = array();
224 $options['options']['enabled'] = get_option('wpcaptcha_enable') !== false ? get_option('wpcaptcha_enable') : 'no';
225 $options['options']['show_login'] = get_option('wpcaptcha_login') !== false ? get_option('wpcaptcha_login') : 'yes';
226 $options['options']['show_registration'] = get_option('wpcaptcha_register') !== false ? get_option('wpcaptcha_register') : 'yes';
227 $options['options']['show_lost_password'] = get_option('wpcaptcha_lost') !== false ? get_option('wpcaptcha_lost') : 'yes';
228 $options['options']['show_comments'] = get_option('wpcaptcha_comments') !== false ? get_option('wpcaptcha_comments') : 'yes';
229 $options['options']['show_logged_in'] = get_option('wpcaptcha_registered') !== false ? get_option('wpcaptcha_registered') : 'no';
230 $options['options']['captcha_type'] = get_option('wpcaptcha_type') !== false ? get_option('wpcaptcha_type') : 'alphanumeric';
231 $options['options']['captcha_letters'] = get_option('wpcaptcha_letters') !== false ? get_option('wpcaptcha_letters') : 'capital';
232 $options['options']['total_no_of_characters'] = get_option('wpcaptcha_total_no_of_characters') !== false ? get_option('wpcaptcha_total_no_of_characters') : 3;
233
234 $change = true;
235 } else if (!isset($options['options']['enabled'])) {
236 $options['options']['enabled'] = 'yes';
237 $change = true;
238 }
239
240 if (isset($_POST['submit']) && isset($_POST['wpcatpcha_update_admin_options_nonce'])) {
241 if (!wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['wpcatpcha_update_admin_options_nonce'])), 'wpcatpcha_update_admin_options')) {
242 echo '<div id="message" class="updated fade">
243 <p><strong>' . esc_html__('Sorry, your nonce did not verify.', 'captcha-code-authentication') . '</strong></p>
244 </div>';
245 } else {
246 if (isset($_POST['captcha_enabled'])) {
247 $options['options']['enabled'] = sanitize_text_field(wp_unslash($_POST['captcha_enabled']));
248 }
249
250 if (isset($_POST['captcha_show_login'])) {
251 $options['options']['show_login'] = sanitize_text_field(wp_unslash($_POST['captcha_show_login']));
252 }
253
254 if (isset($_POST['captcha_show_registration'])) {
255 $options['options']['show_registration'] = sanitize_text_field(wp_unslash($_POST['captcha_show_registration']));
256 }
257
258 if (isset($_POST['captcha_show_lost_password'])) {
259 $options['options']['show_lost_password'] = sanitize_text_field(wp_unslash($_POST['captcha_show_lost_password']));
260 }
261
262 if (isset($_POST['captcha_show_comments'])) {
263 $options['options']['show_comments'] = sanitize_text_field(wp_unslash($_POST['captcha_show_comments']));
264 }
265
266 if (isset($_POST['captcha_show_logged_in'])) {
267 $options['options']['show_logged_in'] = sanitize_text_field(wp_unslash($_POST['captcha_show_logged_in']));
268 }
269
270 if (isset($_POST['captcha_type'])) {
271 $options['options']['captcha_type'] = sanitize_text_field(wp_unslash($_POST['captcha_type']));
272 }
273
274 if (isset($_POST['captcha_letters'])) {
275 $options['options']['captcha_letters'] = sanitize_text_field(wp_unslash($_POST['captcha_letters']));
276 }
277
278 if (isset($_POST['total_no_of_characters'])) {
279 $options['options']['total_no_of_characters'] = sanitize_text_field(wp_unslash($_POST['total_no_of_characters']));
280 }
281
282 $change = true;
283
284 echo '<div id="message" class="updated fade">
285 <p><strong>' . esc_html__('Options saved.', 'captcha-code-authentication') . '</strong></p>
286 </div>';
287 }
288 }
289
290
291 if ($change) {
292 update_option(WP_CAPTCHA_CODE_OPTIONS, $options, true);
293 }
294
295 self::$options = $options;
296 return $options['options'];
297 } // load_options
298
299 static function get_options()
300 {
301 return self::$options['options'];
302 } // get_options
303
304 static function update_options($key, $data)
305 {
306 if (false === in_array($key, array('meta', 'dismissed_notices', 'options'))) {
307 user_error('Unknown options key.', E_USER_ERROR);
308 return false;
309 }
310
311 self::$options[$key] = $data;
312 $tmp = update_option(WP_CAPTCHA_CODE_OPTIONS, self::$options);
313
314 return $tmp;
315 } // update_options
316
317 static function get_plugin_version()
318 {
319 $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
320
321 return $plugin_data['version'];
322 } // get_plugin_version
323
324 static function admin_menu()
325 {
326 add_options_page(
327 esc_html('Captcha'),
328 esc_html('Captcha'),
329 'manage_options',
330 'captcha-code-authentication',
331 array(__CLASS__, 'options_page')
332 );
333 } // admin_menu
334
335 // add admin bar menu and status
336 static function admin_bar()
337 {
338 global $wp_admin_bar;
339 $options = self::get_options();
340 // only show to admins
341 if (false === current_user_can('administrator') || false === apply_filters('captcha_code_show_admin_bar', true)) { //phpcs:ignore
342 return;
343 }
344
345 if (isset($options['enabled']) && $options['enabled'] == 'yes') {
346 $main_label = '<img style="height: 17px; margin-bottom: -4px; padding-right: 3px; filter: grayscale(100%);" src="' . WP_CAPTCHA_CODE_URL . 'images/wp-captcha-icon.png" alt="' . esc_attr__('Captcha is enabled', 'captcha-code-authentication') . '" title="' . esc_attr__('Captcha is enabled', 'captcha-code-authentication') . '" /> <span class="ab-label">' . esc_attr__('Captcha is', 'captcha-code-authentication') . ' <b style="font-weight: 700;">ON</b></span>';
347 } else {
348 $main_label = '<img style="height: 17px; margin-bottom: -4px; padding-right: 3px; filter: grayscale(100%);" src="' . WP_CAPTCHA_CODE_URL . 'images/wp-captcha-icon.png" alt="' . esc_attr__('Captcha is disabled', 'captcha-code-authentication') . '" title="' . esc_attr__('Captcha is disabled', 'captcha-code-authentication') . '" /> <span class="ab-label">' . esc_attr__('Captcha is', 'captcha-code-authentication') . ' <b style="font-weight: 700;">OFF</b></span>';
349 }
350
351 $wp_admin_bar->add_menu(array(
352 'parent' => '',
353 'id' => 'captcha-code',
354 'title' => $main_label,
355 'href' => admin_url('options-general.php?page=captcha-code-authentication'),
356 'meta' => array('class' => '')
357 ));
358 } // admin_bar
359
360 static function captcha_for_login()
361 {
362 echo '<p class="login-form-captcha">
363 <label><b>' . esc_html__('Captcha', 'captcha-code-authentication') . ' </b> <span class="required">*</span></label>
364 <div style="clear:both;"></div><div style="clear:both;"></div>';
365 self::generate_captcha_image();
366
367 if (isset($_GET['captcha']) && $_GET['captcha'] == 'confirm_error') { //phpcs:ignore
368 echo '<label style="color:#FF0000;" id="capt_err">' . esc_html(sanitize_text_field($_SESSION['captcha_error'] ?? '')) . '</label><div style="clear:both;"></div>';;
369 $_SESSION['captcha_error'] = '';
370 }
371
372 echo '<label>' . esc_html__('Type the text displayed above', 'captcha-code-authentication') . ':</label>
373 <input id="captcha_code" name="captcha_code" size="15" type="text" tabindex="30" />
374 </p>';
375 return true;
376 } // captcha_for_login
377
378 static function captcha_login_errors($errors)
379 {
380 //phpcs:ignore since request can come from non-nonced source
381 if (isset($_REQUEST['action']) && 'register' == sanitize_text_field($_REQUEST['action'])) { //phpcs:ignore
382 return ($errors);
383 }
384
385 if (sanitize_text_field($_SESSION['captcha_code'] ?? '') != sanitize_text_field($_REQUEST['captcha_code'])) { //phpcs:ignore
386 return $errors . '<label id="capt_err" for="captcha_code_error">' . esc_html__('Captcha confirmation error!', 'captcha-code-authentication') . '</label>';
387 }
388 return $errors;
389 } // captcha_login_errors
390
391 static function captcha_login_redirect($url)
392 {
393 /* Captcha mismatch */
394 //phpcs:ignore since request can come from non-nonced source
395 if (empty($_REQUEST['captcha_code']) || (isset($_SESSION['captcha_code']) && esc_html($_SESSION['captcha_code']) != sanitize_text_field($_REQUEST['captcha_code']))) { //phpcs:ignore
396 $_SESSION['captcha_error'] = esc_html__('Incorrect captcha confirmation!', 'captcha-code-authentication');
397 wp_clear_auth_cookie();
398 $request_url = sanitize_text_field(wp_unslash($_SERVER["REQUEST_URI"] ?? ''));
399 return $request_url . "/?captcha='confirm_error'";
400 }
401 /* Captcha match: take to the admin panel */ else {
402 return home_url('/wp-admin/');
403 }
404 } // captcha_login_redirect
405
406 static function captcha_comment_form()
407 {
408 $options = self::get_options();
409
410 if (is_user_logged_in() && $options['show_logged_in'] == 'yes') {
411 return true;
412 }
413
414 echo '<p class="comment-form-captcha">
415 <label><b>' . esc_html__('Captcha', 'captcha-code-authentication') . ' </b><span class="required">*</span></label>
416 <div style="clear:both;"></div><div style="clear:both;"></div>';
417 self::generate_captcha_image();
418 echo '<label>' . esc_html__('Type the text displayed above', 'captcha-code-authentication') . ':</label>
419 <input id="captcha_code" name="captcha_code" size="15" type="text" />
420 <div style="clear:both;"></div>
421 </p>';
422
423 remove_action('comment_form', 'captcha_comment_form');
424
425 return true;
426 } // captcha_comment_form
427
428 static function captcha_comment_post($comment)
429 {
430 $options = self::get_options();
431
432 if (is_user_logged_in() && $options['show_logged_in'] == 'yes') {
433 return $comment;
434 }
435
436 // skip captcha for comment replies from the admin menu
437 if (
438 isset($_REQUEST['action']) && $_REQUEST['action'] == 'replyto-comment' &&
439 (check_ajax_referer('replyto-comment', '_ajax_nonce', false) || check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment', false))
440 ) {
441 // skip captcha
442 return $comment;
443 }
444
445 // Skip captcha for trackback or pingback
446 if ($comment['comment_type'] != '' && $comment['comment_type'] != 'comment') {
447 // skip captcha
448 return $comment;
449 }
450
451 // If captcha is empty
452 if (empty($_REQUEST['captcha_code']))
453 wp_die(esc_html__('CAPTCHA cannot be empty.', 'captcha-code-authentication'));
454
455 // captcha was matched
456 $captcha_code = sanitize_text_field($_SESSION['captcha_code'] ?? '');
457 if ($captcha_code == $_REQUEST['captcha_code']) {
458 return ($comment);
459 } else {
460 wp_die(esc_html__('Error: Incorrect CAPTCHA. Press your browser\'s back button and try again.', 'captcha-code-authentication'));
461 }
462 } // captcha_comment_post
463
464 static function wp_captcha_register($default)
465 {
466 echo '<p class="register-form-captcha">
467 <label><b>' . esc_html__('Captcha', 'captcha-code-authentication') . ' </b><span class="required">*</span></label>
468 <div style="clear:both;"></div><div style="clear:both;"></div>';
469 self::generate_captcha_image();
470 echo '<label>' . esc_html__('Type the text displayed above', 'captcha-code-authentication') . ':</label>
471 <input id="captcha_code" name="captcha_code" size="15" type="text" />
472 </p>';
473 return true;
474 } // wp_captcha_register
475
476 static function captcha_register_post($login, $email, $errors)
477 {
478 //phpcs:ignore since request can come from non-nonced source
479 // If captcha is blank - add error
480 if (isset($_REQUEST['captcha_code']) && "" == $_REQUEST['captcha_code']) { //phpcs:ignore
481 $errors->add('captcha_blank', '<strong>' . esc_html__('ERROR', 'captcha-code-authentication') . '</strong>: ' . esc_html__('Please complete the CAPTCHA.', 'captcha-code-authentication'));
482 return $errors;
483 }
484
485 if (isset($_REQUEST['captcha_code']) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'])) { //phpcs:ignore
486 // captcha was matched
487 } else {
488 $errors->add('captcha_wrong', '<strong>' . esc_html__('ERROR', 'captcha-code-authentication') . '</strong>: ' . esc_html__('That CAPTCHA was incorrect.', 'captcha-code-authentication'));
489 }
490 return ($errors);
491 } // captcha_register_post
492
493 static function captcha_register_validate($results)
494 {
495 //phpcs:ignore since request can come from non-nonced source
496 if (isset($_REQUEST['captcha_code']) && "" == $_REQUEST['captcha_code']) { //phpcs:ignore
497 $results['errors']->add('captcha_blank', '<strong>' . esc_html__('ERROR', 'captcha-code-authentication') . '</strong>: ' . esc_html__('Please complete the CAPTCHA.', 'captcha-code-authentication'));
498 return $results;
499 }
500
501 if (isset($_REQUEST['captcha_code']) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'])) { //phpcs:ignore
502 // captcha was matched
503 } else {
504 $results['errors']->add('captcha_wrong', '<strong>' . esc_html__('ERROR', 'captcha-code-authentication') . '</strong>: ' . esc_html__('That CAPTCHA was incorrect.', 'captcha-code-authentication'));
505 }
506 return ($results);
507 } // captcha_register_validate
508
509 static function captcha_lostpassword($default)
510 {
511 echo '<p class="lost-form-captcha">
512 <label><b>' . esc_html__('Captcha', 'captcha-code-authentication') . ' </b><span class="required">*</span></label>
513 <div style="clear:both;"></div><div style="clear:both;"></div>';
514 self::generate_captcha_image();
515 echo '<label>' . esc_html__('Type the text displayed above', 'captcha-code-authentication') . ':</label>
516 <input id="captcha_code" name="captcha_code" size="15" type="text" />
517 </p>';
518 } // captcha_lostpassword
519
520 static function captcha_lostpassword_post()
521 {
522 //phpcs:ignore since request can come from non-nonced source
523 if (isset($_REQUEST['user_login']) && "" == $_REQUEST['user_login']) //phpcs:ignore
524 return;
525
526 // If captcha doesn't entered
527 if (empty($_REQUEST['captcha_code'])) { //phpcs:ignore
528 wp_die(esc_html__('Please complete the CAPTCHA.', 'captcha-code-authentication'));
529 }
530
531 // Check entered captcha
532 $captcha_code = sanitize_text_field($_SESSION['captcha_code'] ?? '');
533 if (isset($_REQUEST['captcha_code']) && ($captcha_code == $_REQUEST['captcha_code'])) { //phpcs:ignore
534 return;
535 } else {
536 wp_die(esc_html__('Error: Incorrect CAPTCHA. Press your browser\'s back button and try again.', 'captcha-code-authentication'));
537 }
538 } // captcha_lostpassword_post
539
540 static function generate_captcha_image()
541 {
542 $image_width = 120;
543 $image_height = 40;
544
545 $options = self::get_options();
546
547 $font = WP_CAPTCHA_CODE_DIR . '/css/monofont.ttf';
548
549 if (!empty($options['captcha_type']) && $options['captcha_type'] == 'alphanumeric') {
550 switch ($options['captcha_letters']) {
551 case 'capital':
552 $possible_letters = '23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
553 break;
554 case 'small':
555 $possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
556 break;
557 case 'capitalsmall':
558 $possible_letters = '23456789bcdfghjkmnpqrstvwxyzABCEFGHJKMNPRSTVWXYZ';
559 break;
560 default:
561 $possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
562 break;
563 }
564 } elseif (!empty($options['captcha_type']) && $options['captcha_type'] == 'alphabets') {
565 switch ($options['captcha_letters']) {
566 case 'capital':
567 $possible_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
568 break;
569 case 'small':
570 $possible_letters = 'bcdfghjkmnpqrstvwxyz';
571 break;
572 case 'capitalsmall':
573 $possible_letters = 'bcdfghjkmnpqrstvwxyzABCEFGHJKMNPRSTVWXYZ';
574 break;
575 default:
576 $possible_letters = 'abcdefghijklmnopqrstuvwxyz';
577 break;
578 }
579 } elseif (!empty($options['captcha_type']) && $options['captcha_type'] == 'numbers') {
580 $possible_letters = '0123456789';
581 } else {
582 $possible_letters = '0123456789';
583 }
584 $random_dots = 0;
585 $random_lines = 20;
586 $captcha_text_color = "0x142864";
587 $captcha_noice_color = "0x142864";
588
589 $code = '';
590
591 $i = 0;
592 while ($i < $options['total_no_of_characters']) {
593 $code .= substr($possible_letters, wp_rand(0, strlen($possible_letters) - 1), 1);
594 $i++;
595 }
596
597 $font_size = $image_height * 0.75;
598 $image = @imagecreate($image_width, $image_height);
599
600 /* setting the background, text and noise colours here */
601 imagecolorallocate($image, 255, 255, 255);
602
603 $arr_text_color = self::captcha_hexrgb($captcha_text_color);
604 $text_color = imagecolorallocate(
605 $image,
606 $arr_text_color['red'],
607 $arr_text_color['green'],
608 $arr_text_color['blue']
609 );
610
611 $arr_noice_color = self::captcha_hexrgb($captcha_noice_color);
612 $image_noise_color = imagecolorallocate(
613 $image,
614 $arr_noice_color['red'],
615 $arr_noice_color['green'],
616 $arr_noice_color['blue']
617 );
618
619 /* generating the dots randomly in background */
620 for ($i = 0; $i < $random_dots; $i++) {
621 imagefilledellipse($image, wp_rand(0, $image_width), wp_rand(0, $image_height), 2, 3, $image_noise_color);
622 }
623
624 /* generating lines randomly in background of image */
625 for ($i = 0; $i < $random_lines; $i++) {
626 imageline($image, wp_rand(0, $image_width), wp_rand(0, $image_height), wp_rand(0, $image_width), wp_rand(0, $image_height), $image_noise_color);
627 }
628
629 /* create a text box and add 6 letters code in it */
630 $textbox = imagettfbbox($font_size, 0, $font, $code);
631 $x = ($image_width - $textbox[4]) / 2;
632 $y = ($image_height - $textbox[5]) / 2;
633 imagettftext($image, $font_size, 0, (int)$x, (int)$y, $text_color, $font, $code);
634
635 ob_start();
636 imagejpeg($image); //showing the image
637 echo '<img src="data:image/png;base64,' . esc_html(base64_encode(ob_get_clean())) . '" width="100">';
638
639 $_SESSION['captcha_code'] = $code;
640 } // generate_captcha_image
641
642 static function captcha_hexrgb($hexstr)
643 {
644 $int = hexdec($hexstr);
645
646 return array(
647 "red" => 0xFF & ($int >> 0x10),
648 "green" => 0xFF & ($int >> 0x8),
649 "blue" => 0xFF & $int
650 );
651 } // captcha_hexrgb
652
653 static function create_select_options($options, $selected = null, $output = true)
654 {
655 $out = "\n";
656
657 foreach ($options as $tmp) {
658 if ((is_array($selected) && in_array($tmp['val'], $selected)) || $selected == $tmp['val']) {
659 $out .= "<option selected=\"selected\" value=\"{$tmp['val']}\" " . (isset($tmp['class']) ? "class=\"{$tmp['class']}\"" : "") . ">{$tmp['label']}&nbsp;</option>\n";
660 } else {
661 $out .= "<option value=\"{$tmp['val']}\" " . (isset($tmp['class']) ? "class=\"{$tmp['class']}\"" : "") . ">{$tmp['label']}&nbsp;</option>\n";
662 }
663 }
664
665 if ($output) {
666 self::wp_kses_wf($out);
667 } else {
668 return $out;
669 }
670 } // create_select_options
671
672 static function options_page()
673 {
674 $options = self::get_options();
675
676 // auto remove welcome pointer when options are opened
677 $pointers = get_option(WP_CAPTCHA_CODE_POINTERS_KEY);
678 if (isset($pointers['welcome'])) {
679 unset($pointers['welcome']);
680 update_option(WP_CAPTCHA_CODE_POINTERS_KEY, $pointers);
681 }
682
683 echo '<div class="wrap">';
684 echo '<h1><img src="' . esc_url(WP_CAPTCHA_CODE_URL . '/images/wp-captcha-logo.png') . '" alt="WP Captcha PRO" title="WP Captcha PRO"></h1>';
685 echo '<form method="post" action="">';
686 echo '<div id="wp_captcha_code_settings">';
687 wp_nonce_field('wpcatpcha_update_admin_options', 'wpcatpcha_update_admin_options_nonce');
688 echo '<table class="form-table">';
689 $captcha = array();
690 $captcha[] = array('val' => 'builtin', 'label' => 'Built-in Captcha');
691 $captcha[] = array('val' => 'icons', 'label' => 'Built-in Icon Captcha', 'class' => 'pro-option');
692 $captcha[] = array('val' => 'recaptchav2', 'label' => 'Google reCAPTCHA v2', 'class' => 'pro-option');
693 $captcha[] = array('val' => 'recaptchav3', 'label' => 'Google reCAPTCHA v3', 'class' => 'pro-option');
694 $captcha[] = array('val' => 'hcaptcha', 'label' => 'hCaptcha', 'class' => 'pro-option');
695 $captcha[] = array('val' => 'cloudflare', 'label' => 'Cloudflare Turnstile', 'class' => 'pro-option');
696
697 echo '<tr valign="top">
698 <th scope="row"><label for="captcha_enabled">' . esc_html__('Enable Captcha Protection', 'captcha-code-authentication') . ':</label></th>
699 <td>
700 <select name="captcha_enabled" id="captcha_enabled" style="width:75px;margin:0;">
701 <option value="yes" ' . ($options['enabled'] == 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('Yes', 'captcha-code-authentication') . '</option>
702 <option value="no" ' . ($options['enabled'] != 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('No', 'captcha-code-authentication') . '</option>
703 </select>
704 </td>
705 </tr>';
706 echo '<tr valign="top">
707 <th scope="row"><label for="captcha">Captcha Type:</label></th>
708 <td><select id="cc-captcha" name="">';
709 self::create_select_options($captcha, 'builtin');
710 echo '</select>';
711 echo '</td></tr>';
712 echo '<tr valign="top">
713 <th scope="row" style="width:260px;"><label for="captcha_letters">' . esc_html__('Select Captcha letters type', 'captcha-code-authentication') . ':</label></th>
714 <td>
715 <select id="captcha_letters" name="captcha_letters" style="margin:0;">
716 <option value="capital" ' . ($options['captcha_letters'] == 'capital' ? 'selected="selected"' : '') . '>' . esc_html__('Capital letters only', 'captcha-code-authentication') . '</option>
717 <option value="small" ' . ($options['captcha_letters'] == 'small' ? 'selected="selected"' : '') . '>' . esc_html__('Small letters only', 'captcha-code-authentication') . '</option>
718 <option value="capitalsmall" ' . ($options['captcha_letters'] == 'capitalsmall' ? 'selected="selected"' : '') . '>' . esc_html__('Capital & Small letters', 'captcha-code-authentication') . '</option>
719 </select>
720 </td>
721 </tr>
722 <tr valign="top">
723 <th scope="row"><label for="captcha_type">' . esc_html__('Select a Captcha type', 'captcha-code-authentication') . ':</label></th>
724 <td>
725 <select id="captcha_type" name="captcha_type" style="margin:0;">
726 <option value="alphanumeric" ' . ($options['captcha_type'] == 'alphanumeric' ? 'selected="selected"' : '') . '>' . esc_html__('Alphanumeric', 'captcha-code-authentication') . '</option>
727 <option value="alphabets" ' . ($options['captcha_type'] == 'alphabets' ? 'selected="selected"' : '') . '>' . esc_html__('Alphabets only', 'captcha-code-authentication') . '</option>
728 <option value="numbers" ' . ($options['captcha_type'] == 'numbers' ? 'selected="selected"' : '') . '>' . esc_html__('Numbers only', 'captcha-code-authentication') . '</option>
729 </select>
730 </td>
731 </tr>
732 <tr valign="top">
733 <th scope="row"><label for="total_no_of_characters">' . esc_html__('Total number of Captcha Characters', 'captcha-code-authentication') . ':</label></th>
734 <td>
735 <select id="total_no_of_characters" name="total_no_of_characters" style="margin:0;width: 50px;">';
736 for ($i = 3; $i <= 6; $i++) {
737 echo '<option value="' . intval($i) . '" ';
738 if ($options['total_no_of_characters'] == $i) echo 'selected="selected"';
739 echo '>' . intval($i) . '</option>';
740 }
741 echo '</select>
742 </td>
743 </tr>
744 <tr valign="top">
745 <th scope="row"><label for="stats">' . esc_html__('Stats', 'captcha-code-authentication') . ':</label></th>
746 <td>
747 <a href="#" class="button open-upsell" data-feature="cc-stats">Show Stats</a><p class="description">This is a <b>PRO</b> feature.</p></a>
748 </td>
749 </tr>
750 <tr valign="top">
751 <th scope="row"><label for="firewall">' . esc_html__('Firewall & Country Blocking', 'captcha-code-authentication') . ':</label></th>
752 <td>
753 <a href="#" class="button open-upsell" data-feature="cc-firewall">Configure Firewall</a><p class="description">This is a <b>PRO</b> feature.</p></a>
754 </td>
755 </tr>
756 <tr height="60">
757 <td>';
758 submit_button();
759 echo '</td>
760 <td></td>
761 </tr>
762 </table>
763 <h3>' . esc_html__('Display Options', 'captcha-code-authentication') . '</h3>
764 <table class="form-table">
765 <tr valign="top">
766 <th scope="row" style="width:260px;"><label for="captcha_show_login">' . esc_html__("Enable Captcha for Login form", "captcha-code-authentication") . ':</label></th>
767 <td>
768 <select name="captcha_show_login" id="captcha_show_login" style="width:75px;margin:0;">
769 <option value="yes" ' . ($options['show_login'] == 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('Yes', 'captcha-code-authentication') . '</option>
770 <option value="no" ' . ($options['show_login'] != 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('No', 'captcha-code-authentication') . '</option>
771 </select>
772 </td>
773 </tr>
774 <tr valign="top">
775 <th scope="row"><label for="captcha_show_registration">' . esc_html__('Enable Captcha for Register form', 'captcha-code-authentication') . ':</label></th>
776 <td>
777 <select name="captcha_show_registration" id="captcha_show_registration" style="width:75px;margin:0;">
778 <option value="yes" ' . ($options['show_registration'] == 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('Yes', 'captcha-code-authentication') . '</option>
779 <option value="no" ' . ($options['show_registration'] != 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('No', 'captcha-code-authentication') . '</option>
780 </select>
781 </td>
782 </tr>
783 <tr valign="top">
784 <th scope="row"><label for="captcha_show_lost_password">' . esc_html__('Enable Captcha for Lost Password form', 'captcha-code-authentication') . ':</label></th>
785 <td>
786 <select name="captcha_show_lost_password" id="captcha_show_lost_password" style="width:75px;margin:0;">
787 <option value="yes" ' . ($options['show_lost_password'] == 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('Yes', 'captcha-code-authentication') . '</option>
788 <option value="no" ' . ($options['show_lost_password'] != 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('No', 'captcha-code-authentication') . '</option>
789 </select>
790 </td>
791 </tr>
792 <tr valign="top">
793 <th scope="row"><label for="captcha_show_comments">' . esc_html__('Enable Captcha for Comments form', 'captcha-code-authentication') . ':</label></th>
794 <td>
795 <select name="captcha_show_comments" id="captcha_show_comments" style="width:75px;margin:0;">
796 <option value="yes" ' . ($options['show_comments'] == 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('Yes', 'captcha-code-authentication') . '</option>
797 <option value="no" ' . ($options['show_comments'] != 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('No', 'captcha-code-authentication') . '</option>
798 </select>
799 </td>
800 </tr>
801 <tr valign="top">
802 <th scope="row"><label for="captcha_show_logged_in">' . esc_html__('Hide Captcha for logged in users', 'captcha-code-authentication') . ':</label></th>
803 <td>
804 <select name="captcha_show_logged_in" id="captcha_show_logged_in" style="width:75px;margin:0;">
805 <option value="yes" ' . ($options['show_logged_in'] == 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('Yes', 'captcha-code-authentication') . '</option>
806 <option value="no" ' . ($options['show_logged_in'] != 'yes' ? 'selected="selected"' : '') . '>' . esc_html__('No', 'captcha-code-authentication') . '</option>
807 </select>
808 </td>
809 </tr>
810 <tr height="60">
811 <td>';
812 submit_button();
813 echo '</td>
814 <td></td>
815 </tr>
816 </table>';
817
818 echo '</div>';
819
820 echo '<div id="wp_captcha_code_sidebar">';
821 echo '<div class="sidebar-box pro-ad-box">
822 <p class="text-center"><a href="#" data-pro-feature="cc-sidebar-box-logo" class="open-pro-dialog">
823 <img src="' . esc_url(WP_CAPTCHA_CODE_URL . '/images/wp-captcha-logo.png') . '" alt="WP Captcha PRO" title="WP Captcha PRO"></a><br><b>Get the PRO version for ONLY $9.99</b></p>
824 <ul class="plain-list">
825 <li>7 Types of Captcha + GDPR Compatibility</li>
826 <li>Login Page Customization - Visual &amp; URL</li>
827 <li>Advanced Login Page Protection</li>
828 <li>Email Based Two Factor Authentication (2FA)</li>
829 <li>Advanced Firewall + Cloud Blacklists</li>
830 <li>Country Blocking (whitelist &amp; blacklist)</li>
831 <li>Temporary Access Links</li>
832 <li>Recovery URL - You Can Never Get Locked Out</li>
833 <li>Licenses &amp; Sites Manager (remote SaaS dashboard)</li>
834 <li>White-label Mode</li>
835 <li>Complete Codeless Plugin Rebranding</li>
836 <li>Email support from plugin developers</li>
837 </ul>
838
839 <p class="text-center"><a href="#" class="open-pro-dialog button button-buy" data-pro-feature="cc-sidebar-box">Get PRO Now for ONLY $9.99</a></p>
840 </div>';
841
842 if (!defined('EPS_REDIRECT_VERSION') && !defined('WF301_PLUGIN_FILE')) {
843 echo '<div class="sidebar-box pro-ad-box box-301">
844 <h3 class="textcenter"><b>Problems with redirects?<br>Moving content around or changing posts\' URL?<br>Old URLs giving you problems?<br><br><u>Improve your SEO &amp; manage all redirects in one place!</u></b></h3>
845
846 <p class="text-center"><a href="#" class="install-wp301">
847 <img src="' . esc_url(WP_CAPTCHA_CODE_URL . '/images/wp-301-logo.png') . '" alt="WP 301 Redirects" title="WP 301 Redirects"></a></p>
848
849 <p class="text-center"><a href="#" class="button button-buy install-wp301">Install and activate the <u>free</u> WP 301 Redirects plugin</a></p>
850
851 <p><a href="https://wordpress.org/plugins/eps-301-redirects/" target="_blank">WP 301 Redirects</a> is a free WP plugin maintained by the same team as this WP Captcha plugin. It has <b>+250,000 users, 5-star rating</b>, and is hosted on the official WP repository.</p>
852 </div>';
853 }
854
855 echo '<div class="sidebar-box" style="margin-top: 35px; margin-bottom: 35px;">
856 <p>Need help? Ask on the <a href="https://wordpress.org/support/plugin/captcha-code-authentication/" target="_blank">support forum</a>. We\'ll answer ASAP!</p>
857 <p>Please <a href="https://wordpress.org/support/plugin/captcha-code-authentication/reviews/#new-post" target="_blank">rate the plugin �
858 �
859 �
860 �
861 �
862 </a> to <b>keep it up-to-date &amp; maintained</b>. It only takes a second to rate. Thank you! 👋</p>
863 </div>';
864 echo '</div>';
865
866 echo '</form>';
867
868 echo ' <div id="wp-captcha-code-pro-dialog" style="display: none;" title="WP Captcha PRO is here!"><span class="ui-helper-hidden-accessible"><input type="text"/></span>
869
870 <div class="center logo"><a href="https://getwpcaptcha.com/?ref=wp-captcha-code-free-pricing-table" target="_blank"><img src="' . esc_url(WP_CAPTCHA_CODE_URL . '/images/wp-captcha-logo.png') . '" alt="WP Captcha PRO" title="WP Captcha PRO"></a><br>
871
872 <span>Grab our recession-proof <b>DISCOUNTED PRICES</b></span>
873 </div>
874
875 <table id="wp-captcha-code-pro-table">
876 <tr>
877 <td class="center">Personal License</td>
878 <td class="center">Team License</td>
879 <td class="center">Agency License</td>
880 </tr>
881
882 <tr class="prices">
883 <td class="center"><span><del>$59</del> $49</span> <b>/year</b></td>
884 <td class="center"><span><del>$119</del> $99</span> <b>/year</b></td>
885 <td class="center"><span><del>$149</del> $119</span> <b>/year</b></td>
886 </tr>
887
888 <tr>
889 <td><span class="dashicons dashicons-yes"></span><b>1 Site License</b> ($49 per site)</td>
890 <td><span class="dashicons dashicons-yes"></span><b>5 Sites License</b> ($20 per site)</td>
891 <td><span class="dashicons dashicons-yes"></span><b>100 Sites License</b> ($1.2 per site)</td>
892 </tr>
893
894 <tr>
895 <td><span class="dashicons dashicons-yes"></span>All Plugin Features</td>
896 <td><span class="dashicons dashicons-yes"></span>All Plugin Features</td>
897 <td><span class="dashicons dashicons-yes"></span>All Plugin Features</td>
898 </tr>
899
900 <tr>
901 <td><span class="dashicons dashicons-yes"></span>7 Types of Captcha</td>
902 <td><span class="dashicons dashicons-yes"></span>7 Types of Captcha</td>
903 <td><span class="dashicons dashicons-yes"></span>7 Types of Captcha</td>
904 </tr>
905
906 <tr>
907 <td><span class="dashicons dashicons-yes"></span>Advanced Firewall + Cloud Blacklists</td>
908 <td><span class="dashicons dashicons-yes"></span>Advanced Firewall + Cloud Blacklists</td>
909 <td><span class="dashicons dashicons-yes"></span>Advanced Firewall + Cloud Blacklists</td>
910 </tr>
911
912 <tr>
913 <td><span class="dashicons dashicons-yes"></span>Login Page Customization</td>
914 <td><span class="dashicons dashicons-yes"></span>Login Page Customization</td>
915 <td><span class="dashicons dashicons-yes"></span>Login Page Customization</td>
916 </tr>
917
918 <tr>
919 <td><span class="dashicons dashicons-yes"></span>Email Based 2FA</td>
920 <td><span class="dashicons dashicons-yes"></span>Email Based 2FA</td>
921 <td><span class="dashicons dashicons-yes"></span>Email Based 2FA</td>
922 </tr>
923
924 <tr>
925 <td><span class="dashicons dashicons-yes"></span>Temporary Access Links</td>
926 <td><span class="dashicons dashicons-yes"></span>Temporary Access Links</td>
927 <td><span class="dashicons dashicons-yes"></span>Temporary Access Links</td>
928 </tr>
929
930 <tr>
931 <td><span class="dashicons dashicons-yes"></span>Country Blocking</td>
932 <td><span class="dashicons dashicons-yes"></span>Country Blocking</td>
933 <td><span class="dashicons dashicons-yes"></span>Country Blocking</td>
934 </tr>
935
936 <tr>
937 <td><span class="dashicons dashicons-yes"></span>SaaS Dashboard</td>
938 <td><span class="dashicons dashicons-yes"></span>SaaS Dashboard</td>
939 <td><span class="dashicons dashicons-yes"></span>SaaS Dashboard</td>
940 </tr>
941
942 <tr>
943 <td><span class="dashicons dashicons-no"></span>White-label Mode</td>
944 <td><span class="dashicons dashicons-yes"></span>White-label Mode</td>
945 <td><span class="dashicons dashicons-yes"></span>White-label Mode</td>
946 </tr>
947
948 <tr>
949 <td><span class="dashicons dashicons-no"></span>Full Plugin Rebranding</td>
950 <td><span class="dashicons dashicons-no"></span>Full Plugin Rebranding</td>
951 <td><span class="dashicons dashicons-yes"></span>Full Plugin Rebranding</td>
952 </tr>
953
954 <tr>
955 <td><a class="button button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=personal-yearly-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=personal-yearly-launch&ref=pricing-table" target="_blank"><del>$59</del> $49 <small>/y</small><br>BUY NOW</a></td>
956 <td><a class="button button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=team-yearly-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=team-yearly-launch&ref=pricing-table" target="_blank"><del>$119</del> $99 <small>/y</small><br>BUY NOW</a></td>
957 <td><a class="button button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=agency-yearly-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=agency-yearly-launch&ref=pricing-table" target="_blank"><del>$149</del> $119 <small>/y</small><br>BUY NOW</a></td>
958 </tr>
959
960 </table>
961
962 <div class="upsell-footer-2 center">Need the plugin only for a <b>short period of time</b>? <a class="button-buy" target="_blank" data-href-org="https://getwpcaptcha.com/buy/?product=personal-monthly&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=personal-monthly&ref=pricing-table"><b>Get it for ONLY $9.99</b><small> /month</small></a> &amp; cancel any time!</div>
963
964 <div class="center footer"><b>100% No-Risk Money Back Guarantee!</b> If you don\'t like the plugin over the next 7 days, we will happily refund 100% of your money. No questions asked! Payments are processed by our merchant of records - <a href="https://paddle.com/" target="_blank">Paddle</a>.</div>
965 </div>';
966 echo '</div>';
967 } // options_page
968
969 static function install_wp301()
970 {
971 check_ajax_referer('install_wp301');
972
973 if (false === current_user_can('administrator')) {
974 wp_die('Sorry, you have to be an admin to run this action.');
975 }
976
977 $plugin_slug = 'eps-301-redirects/eps-301-redirects.php';
978 $plugin_zip = 'https://downloads.wordpress.org/plugin/eps-301-redirects.latest-stable.zip';
979
980 @include_once ABSPATH . 'wp-admin/includes/plugin.php';
981 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
982 @include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
983 @include_once ABSPATH . 'wp-admin/includes/file.php';
984 @include_once ABSPATH . 'wp-admin/includes/misc.php';
985 echo '<style>
986 body{
987 font-family: sans-serif;
988 font-size: 14px;
989 line-height: 1.5;
990 color: #444;
991 }
992 </style>';
993
994 echo '<div style="margin: 20px; color:#444;">';
995 echo 'If things are not done in a minute <a target="_parent" href="' . esc_url(admin_url('plugin-install.php?s=301%20redirects%20webfactory&tab=search&type=term')) . '">install the plugin manually via Plugins page</a><br><br>';
996 echo 'Starting ...<br><br>';
997
998 wp_cache_flush();
999 $upgrader = new Plugin_Upgrader();
1000 echo 'Check if WP 301 Redirects is already installed ... <br />';
1001 if (self::is_plugin_installed($plugin_slug)) {
1002 echo 'WP 301 Redirects is already installed! <br /><br />Making sure it\'s the latest version.<br />';
1003 $upgrader->upgrade($plugin_slug);
1004 $installed = true;
1005 } else {
1006 echo 'Installing WP 301 Redirects.<br />';
1007 $installed = $upgrader->install($plugin_zip);
1008 }
1009 wp_cache_flush();
1010
1011 if (!is_wp_error($installed) && $installed) {
1012 echo 'Activating WP 301 Redirects.<br />';
1013 $activate = activate_plugin($plugin_slug);
1014
1015 if (is_null($activate)) {
1016 echo 'WP 301 Redirects Activated.<br />';
1017
1018 echo '<script>setTimeout(function() { top.location = "' . esc_url(admin_url('options-general.php?page=eps_redirects')) . '"; }, 1000);</script>';
1019 echo '<br>If you are not redirected in a few seconds - <a href="' . esc_url(admin_url('options-general.php?page=eps_redirects')) . '" target="_parent">click here</a>.';
1020 }
1021 } else {
1022 echo 'Could not install WP 301 Redirects. You\'ll have to <a target="_parent" href="' . esc_url(admin_url('plugin-install.php?s=301%20redirects%20webfactory&tab=search&type=term')) . '">download and install manually</a>.';
1023 }
1024
1025 echo '</div>';
1026 } // install_wp301
1027
1028 static function is_plugin_installed($slug)
1029 {
1030 if (!function_exists('get_plugins')) {
1031 require_once ABSPATH . 'wp-admin/includes/plugin.php';
1032 }
1033 $all_plugins = get_plugins();
1034
1035 if (!empty($all_plugins[$slug])) {
1036 return true;
1037 } else {
1038 return false;
1039 }
1040 } // is_plugin_installed
1041
1042 static function wp_kses_wf($html)
1043 {
1044 add_filter('safe_style_css', function ($styles) {
1045 $styles_wf = array(
1046 'text-align',
1047 'margin',
1048 'color',
1049 'float',
1050 'border',
1051 'background',
1052 'background-color',
1053 'border-bottom',
1054 'border-bottom-color',
1055 'border-bottom-style',
1056 'border-bottom-width',
1057 'border-collapse',
1058 'border-color',
1059 'border-left',
1060 'border-left-color',
1061 'border-left-style',
1062 'border-left-width',
1063 'border-right',
1064 'border-right-color',
1065 'border-right-style',
1066 'border-right-width',
1067 'border-spacing',
1068 'border-style',
1069 'border-top',
1070 'border-top-color',
1071 'border-top-style',
1072 'border-top-width',
1073 'border-width',
1074 'caption-side',
1075 'clear',
1076 'cursor',
1077 'direction',
1078 'font',
1079 'font-family',
1080 'font-size',
1081 'font-style',
1082 'font-variant',
1083 'font-weight',
1084 'height',
1085 'letter-spacing',
1086 'line-height',
1087 'margin-bottom',
1088 'margin-left',
1089 'margin-right',
1090 'margin-top',
1091 'overflow',
1092 'padding',
1093 'padding-bottom',
1094 'padding-left',
1095 'padding-right',
1096 'padding-top',
1097 'text-decoration',
1098 'text-indent',
1099 'vertical-align',
1100 'width',
1101 'display',
1102 );
1103
1104 foreach ($styles_wf as $style_wf) {
1105 $styles[] = $style_wf;
1106 }
1107 return $styles;
1108 });
1109
1110 $allowed_tags = wp_kses_allowed_html('post');
1111 $allowed_tags['input'] = array(
1112 'type' => true,
1113 'style' => true,
1114 'class' => true,
1115 'id' => true,
1116 'checked' => true,
1117 'disabled' => true,
1118 'name' => true,
1119 'size' => true,
1120 'placeholder' => true,
1121 'value' => true,
1122 'data-*' => true,
1123 'size' => true,
1124 'disabled' => true
1125 );
1126
1127 $allowed_tags['textarea'] = array(
1128 'type' => true,
1129 'style' => true,
1130 'class' => true,
1131 'id' => true,
1132 'checked' => true,
1133 'disabled' => true,
1134 'name' => true,
1135 'size' => true,
1136 'placeholder' => true,
1137 'value' => true,
1138 'data-*' => true,
1139 'cols' => true,
1140 'rows' => true,
1141 'disabled' => true,
1142 'autocomplete' => true
1143 );
1144
1145 $allowed_tags['select'] = array(
1146 'type' => true,
1147 'style' => true,
1148 'class' => true,
1149 'id' => true,
1150 'checked' => true,
1151 'disabled' => true,
1152 'name' => true,
1153 'size' => true,
1154 'placeholder' => true,
1155 'value' => true,
1156 'data-*' => true,
1157 'multiple' => true,
1158 'disabled' => true
1159 );
1160
1161 $allowed_tags['option'] = array(
1162 'type' => true,
1163 'style' => true,
1164 'class' => true,
1165 'id' => true,
1166 'checked' => true,
1167 'disabled' => true,
1168 'name' => true,
1169 'size' => true,
1170 'placeholder' => true,
1171 'value' => true,
1172 'selected' => true,
1173 'data-*' => true
1174 );
1175
1176 $allowed_tags['optgroup'] = array(
1177 'type' => true,
1178 'style' => true,
1179 'class' => true,
1180 'id' => true,
1181 'checked' => true,
1182 'disabled' => true,
1183 'name' => true,
1184 'size' => true,
1185 'placeholder' => true,
1186 'value' => true,
1187 'selected' => true,
1188 'data-*' => true,
1189 'label' => true
1190 );
1191
1192 $allowed_tags['a'] = array(
1193 'href' => true,
1194 'data-*' => true,
1195 'class' => true,
1196 'style' => true,
1197 'id' => true,
1198 'target' => true,
1199 'data-*' => true,
1200 'role' => true,
1201 'aria-controls' => true,
1202 'aria-selected' => true,
1203 'disabled' => true
1204 );
1205
1206 $allowed_tags['div'] = array(
1207 'style' => true,
1208 'class' => true,
1209 'id' => true,
1210 'data-*' => true,
1211 'role' => true,
1212 'aria-labelledby' => true,
1213 'value' => true,
1214 'aria-modal' => true,
1215 'tabindex' => true
1216 );
1217
1218 $allowed_tags['li'] = array(
1219 'style' => true,
1220 'class' => true,
1221 'id' => true,
1222 'data-*' => true,
1223 'role' => true,
1224 'aria-labelledby' => true,
1225 'value' => true,
1226 'aria-modal' => true,
1227 'tabindex' => true
1228 );
1229
1230 $allowed_tags['span'] = array(
1231 'style' => true,
1232 'class' => true,
1233 'id' => true,
1234 'data-*' => true,
1235 'aria-hidden' => true
1236 );
1237
1238 $allowed_tags['style'] = array(
1239 'class' => true,
1240 'id' => true,
1241 'type' => true,
1242 'style' => true
1243 );
1244
1245 $allowed_tags['fieldset'] = array(
1246 'class' => true,
1247 'id' => true,
1248 'type' => true,
1249 'style' => true
1250 );
1251
1252 $allowed_tags['link'] = array(
1253 'class' => true,
1254 'id' => true,
1255 'type' => true,
1256 'rel' => true,
1257 'href' => true,
1258 'media' => true,
1259 'style' => true
1260 );
1261
1262 $allowed_tags['form'] = array(
1263 'style' => true,
1264 'class' => true,
1265 'id' => true,
1266 'method' => true,
1267 'action' => true,
1268 'data-*' => true,
1269 'style' => true
1270 );
1271
1272 $allowed_tags['script'] = array(
1273 'class' => true,
1274 'id' => true,
1275 'type' => true,
1276 'src' => true,
1277 'style' => true
1278 );
1279
1280 $allowed_tags['table'] = array(
1281 'class' => true,
1282 'id' => true,
1283 'type' => true,
1284 'cellpadding' => true,
1285 'cellspacing' => true,
1286 'border' => true,
1287 'style' => true
1288 );
1289
1290 $allowed_tags['canvas'] = array(
1291 'class' => true,
1292 'id' => true,
1293 'style' => true
1294 );
1295
1296 echo wp_kses($html, $allowed_tags);
1297
1298 add_filter('safe_style_css', function ($styles) {
1299 $styles_wf = array(
1300 'text-align',
1301 'margin',
1302 'color',
1303 'float',
1304 'border',
1305 'background',
1306 'background-color',
1307 'border-bottom',
1308 'border-bottom-color',
1309 'border-bottom-style',
1310 'border-bottom-width',
1311 'border-collapse',
1312 'border-color',
1313 'border-left',
1314 'border-left-color',
1315 'border-left-style',
1316 'border-left-width',
1317 'border-right',
1318 'border-right-color',
1319 'border-right-style',
1320 'border-right-width',
1321 'border-spacing',
1322 'border-style',
1323 'border-top',
1324 'border-top-color',
1325 'border-top-style',
1326 'border-top-width',
1327 'border-width',
1328 'caption-side',
1329 'clear',
1330 'cursor',
1331 'direction',
1332 'font',
1333 'font-family',
1334 'font-size',
1335 'font-style',
1336 'font-variant',
1337 'font-weight',
1338 'height',
1339 'letter-spacing',
1340 'line-height',
1341 'margin-bottom',
1342 'margin-left',
1343 'margin-right',
1344 'margin-top',
1345 'overflow',
1346 'padding',
1347 'padding-bottom',
1348 'padding-left',
1349 'padding-right',
1350 'padding-top',
1351 'text-decoration',
1352 'text-indent',
1353 'vertical-align',
1354 'width'
1355 );
1356
1357 foreach ($styles_wf as $style_wf) {
1358 if (($key = array_search($style_wf, $styles)) !== false) {
1359 unset($styles[$key]);
1360 }
1361 }
1362 return $styles;
1363 });
1364 } // is_plugin_installed
1365
1366 static function activate()
1367 {
1368 self::reset_pointers();
1369 } // activate
1370 } // WP_Captcha_Code
1371
1372 register_activation_hook(__FILE__, array('WP_Captcha_Code', 'activate'));
1373 add_action('init', array('WP_Captcha_Code', 'init'));
1374
1375