PluginProbe
Captcha Code / 3.3
Captcha Code v3.3
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 3.3, at wpCaptcha.php

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