Configure Captcha'; $pro_link = 'Get PRO'; array_unshift($links, $settings_link); array_unshift($links, $pro_link); return $links; } // plugin_action_links static function admin_enqueue_scripts($hook) { if ('settings_page_captcha-code-authentication' == $hook) { wp_enqueue_style('wp-jquery-ui-dialog'); wp_enqueue_style('wp-captcha-code-admin', WP_CAPTCHA_CODE_URL . 'css/wp-captcha-code.css', array(), self::$version); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-position'); wp_enqueue_script('jquery-effects-core'); wp_enqueue_script('jquery-effects-blind'); wp_enqueue_script('jquery-ui-dialog'); $js_localize = array( 'wp301_install_url' => add_query_arg(array('action' => 'wp_captcha_code_install_wp301', '_wpnonce' => wp_create_nonce('install_wp301'), 'rnd' => rand()), admin_url('admin.php')) ); wp_enqueue_script('wp-captcha-code-admin', WP_CAPTCHA_CODE_URL . 'js/wp-captcha-code.js', array('jquery'), self::$version, true); wp_localize_script('wp-captcha-code-admin', 'wp_captcha_code_vars', $js_localize); } } // admin_enqueue_scripts static function is_plugin_page() { $current_screen = get_current_screen(); if ($current_screen->id == 'settings_page_captcha-code-authentication') { return true; } else { return false; } } // is_plugin_page static function admin_footer_text($text) { if (!self::is_plugin_page()) { return $text; } $text = 'Captcha Code v' . self::$version . ' WebFactory Ltd. Please rate the plugin ★★★★★ to help us spread the word. Thank you 🙌 from the WebFactory team!'; return $text; } // admin_footer_text static function generate_web_link($placement = '', $page = '/', $params = array(), $anchor = '') { $base_url = 'https://getwpcaptcha.com'; if ('/' != $page) { $page = '/' . trim($page, '/') . '/'; } if ($page == '//') { $page = '/'; } $parts = array_merge(array('utm_source' => 'captcha-code-authentication', 'utm_content' => $placement), $params); if (!empty($anchor)) { $anchor = '#' . trim($anchor, '#'); } $out = $base_url . $page . '?' . http_build_query($parts, '', '&') . $anchor; return $out; } // generate_web_link static function load_options() { $options = get_option(WP_CAPTCHA_CODE_OPTIONS, array()); $change = false; if (!isset($options['meta'])) { $options['meta'] = array('first_version' => self::$version, 'first_install' => current_time('timestamp', true)); $change = true; } if (!isset($options['dismissed_notices'])) { $options['dismissed_notices'] = array(); $change = true; } if (!isset($options['options'])) { $options['options'] = array(); $options['options']['show_login'] = get_option('wpcaptcha_login') !== false ? get_option('wpcaptcha_login') : 'yes'; $options['options']['show_registration'] = get_option('wpcaptcha_register') !== false ? get_option('wpcaptcha_register') : 'yes'; $options['options']['show_lost_password'] = get_option('wpcaptcha_lost') !== false ? get_option('wpcaptcha_lost') : 'yes'; $options['options']['show_comments'] = get_option('wpcaptcha_comments') !== false ? get_option('wpcaptcha_comments') : 'yes'; $options['options']['show_logged_in'] = get_option('wpcaptcha_registered') !== false ? get_option('wpcaptcha_registered') : 'no'; $options['options']['captcha_type'] = get_option('wpcaptcha_type') !== false ? get_option('wpcaptcha_type') : 'alphanumeric'; $options['options']['captcha_letters'] = get_option('wpcaptcha_letters') !== false ? get_option('wpcaptcha_letters') : 'capital'; $options['options']['total_no_of_characters'] = get_option('wpcaptcha_total_no_of_characters') !== false ? get_option('wpcaptcha_total_no_of_characters') : 3; $change = true; } if (isset($_POST['submit']) && isset($_POST['wpcatpcha_update_admin_options_nonce'])) { if (!wp_verify_nonce($_POST['wpcatpcha_update_admin_options_nonce'], 'wpcatpcha_update_admin_options')) { echo '

' . esc_html__('Sorry, your nonce did not verify.', 'captcha-code-authentication') . '

'; } else { if (isset($_POST['captcha_show_login'])) { $options['options']['show_login'] = sanitize_text_field($_POST['captcha_show_login']); } if (isset($_POST['captcha_show_registration'])) { $options['options']['show_registration'] = sanitize_text_field($_POST['captcha_show_registration']); } if (isset($_POST['captcha_show_lost_password'])) { $options['options']['show_lost_password'] = sanitize_text_field($_POST['captcha_show_lost_password']); } if (isset($_POST['captcha_show_comments'])) { $options['options']['show_comments'] = sanitize_text_field($_POST['captcha_show_comments']); } if (isset($_POST['captcha_show_logged_in'])) { $options['options']['show_logged_in'] = sanitize_text_field($_POST['captcha_show_logged_in']); } if (isset($_POST['captcha_type'])) { $options['options']['captcha_type'] = sanitize_text_field($_POST['captcha_type']); } if (isset($_POST['captcha_letters'])) { $options['options']['captcha_letters'] = sanitize_text_field($_POST['captcha_letters']); } if (isset($_POST['total_no_of_characters'])) { $options['options']['total_no_of_characters'] = sanitize_text_field($_POST['total_no_of_characters']); } $change = true; echo '

' . esc_html__('Options saved.', 'captcha-code-authentication') . '

'; } } if ($change) { update_option(WP_CAPTCHA_CODE_OPTIONS, $options, true); } self::$options = $options; return $options['options']; } // load_options static function get_options() { return self::$options['options']; } // get_options static function update_options($key, $data) { if (false === in_array($key, array('meta', 'dismissed_notices', 'options'))) { user_error('Unknown options key.', E_USER_ERROR); return false; } self::$options[$key] = $data; $tmp = update_option(WP_CAPTCHA_CODE_OPTIONS, self::$options); return $tmp; } // update_options static function get_plugin_version() { $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin'); return $plugin_data['version']; } // get_plugin_version static function admin_menu() { add_options_page( esc_html__('Captcha'), esc_html__('Captcha'), 'manage_options', 'captcha-code-authentication', array(__CLASS__, 'options_page') ); } // admin_menu static function captcha_for_login() { echo '

'; self::generate_captcha_image(); if (isset($_GET['captcha']) && $_GET['captcha'] == 'confirm_error') { echo '
';; $_SESSION['captcha_error'] = ''; } echo '

'; return true; } // captcha_for_login static function captcha_login_errors($errors) { if (isset($_REQUEST['action']) && 'register' == sanitize_text_field($_REQUEST['action'])) { return ($errors); } if (esc_html($_SESSION['captcha_code']) != sanitize_text_field($_REQUEST['captcha_code'])) { return $errors . ''; } return $errors; } // captcha_login_errors static function captcha_login_redirect($url) { /* Captcha mismatch */ if (empty($_REQUEST['captcha_code']) || (isset($_SESSION['captcha_code']) && esc_html($_SESSION['captcha_code']) != sanitize_text_field($_REQUEST['captcha_code']))) { $_SESSION['captcha_error'] = esc_html__('Incorrect captcha confirmation!', 'captcha-code-authentication'); wp_clear_auth_cookie(); return $_SERVER["REQUEST_URI"] . "/?captcha='confirm_error'"; } /* Captcha match: take to the admin panel */ else { return home_url('/wp-admin/'); } } // captcha_login_redirect static function captcha_comment_form() { $options = self::get_options(); if (is_user_logged_in() && $options['show_logged_in'] == 'yes') { return true; } echo '

'; self::generate_captcha_image(); echo '

'; remove_action('comment_form', 'captcha_comment_form'); return true; } // captcha_comment_form static function captcha_comment_post($comment) { $options = self::get_options(); if (is_user_logged_in() && $options['show_logged_in'] == 'yes') { return $comment; } // skip captcha for comment replies from the admin menu if ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'replyto-comment' && (check_ajax_referer('replyto-comment', '_ajax_nonce', false) || check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment', false)) ) { // skip captcha return $comment; } // Skip captcha for trackback or pingback if ($comment['comment_type'] != '' && $comment['comment_type'] != 'comment') { // skip captcha return $comment; } // If captcha is empty if (empty($_REQUEST['captcha_code'])) wp_die(esc_html__('CAPTCHA cannot be empty.', 'captcha-code-authentication')); // captcha was matched if ($_SESSION['captcha_code'] == $_REQUEST['captcha_code']) { return ($comment); } else { wp_die(esc_html__('Error: Incorrect CAPTCHA. Press your browser\'s back button and try again.', 'captcha-code-authentication')); } } // captcha_comment_post static function wp_captcha_register($default) { echo '

'; self::generate_captcha_image(); echo '

'; return true; } // wp_captcha_register static function captcha_register_post($login, $email, $errors) { // If captcha is blank - add error if (isset($_REQUEST['captcha_code']) && "" == $_REQUEST['captcha_code']) { $errors->add('captcha_blank', '' . esc_html__('ERROR', 'captcha-code-authentication') . ': ' . esc_html__('Please complete the CAPTCHA.', 'captcha-code-authentication')); return $errors; } if (isset($_REQUEST['captcha_code']) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'])) { // captcha was matched } else { $errors->add('captcha_wrong', '' . esc_html__('ERROR', 'captcha-code-authentication') . ': ' . esc_html__('That CAPTCHA was incorrect.', 'captcha-code-authentication')); } return ($errors); } // captcha_register_post static function captcha_register_validate($results) { if (isset($_REQUEST['captcha_code']) && "" == $_REQUEST['captcha_code']) { $results['errors']->add('captcha_blank', '' . esc_html__('ERROR', 'captcha-code-authentication') . ': ' . esc_html__('Please complete the CAPTCHA.', 'captcha-code-authentication')); return $results; } if (isset($_REQUEST['captcha_code']) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'])) { // captcha was matched } else { $results['errors']->add('captcha_wrong', '' . esc_html__('ERROR', 'captcha-code-authentication') . ': ' . esc_html__('That CAPTCHA was incorrect.', 'captcha-code-authentication')); } return ($results); } // captcha_register_validate static function captcha_lostpassword($default) { echo '

'; self::generate_captcha_image(); echo '

'; } // captcha_lostpassword static function captcha_lostpassword_post() { if (isset($_REQUEST['user_login']) && "" == $_REQUEST['user_login']) return; // If captcha doesn't entered if (empty($_REQUEST['captcha_code'])) { wp_die(esc_html__('Please complete the CAPTCHA.', 'captcha-code-authentication')); } // Check entered captcha if (isset($_REQUEST['captcha_code']) && ($_SESSION['captcha_code'] == $_REQUEST['captcha_code'])) { return; } else { wp_die(esc_html__('Error: Incorrect CAPTCHA. Press your browser\'s back button and try again.', 'captcha-code-authentication')); } } // captcha_lostpassword_post static function generate_captcha_image() { $image_width = 120; $image_height = 40; $options = self::get_options(); $font = WP_CAPTCHA_CODE_DIR . '/css/monofont.ttf'; if (!empty($options['captcha_type']) && $options['captcha_type'] == 'alphanumeric') { switch ($options['captcha_letters']) { case 'capital': $possible_letters = '23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'small': $possible_letters = '23456789bcdfghjkmnpqrstvwxyz'; break; case 'capitalsmall': $possible_letters = '23456789bcdfghjkmnpqrstvwxyzABCEFGHJKMNPRSTVWXYZ'; break; default: $possible_letters = '23456789bcdfghjkmnpqrstvwxyz'; break; } } elseif (!empty($options['captcha_type']) && $options['captcha_type'] == 'alphabets') { switch ($options['captcha_letters']) { case 'capital': $possible_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'small': $possible_letters = 'bcdfghjkmnpqrstvwxyz'; break; case 'capitalsmall': $possible_letters = 'bcdfghjkmnpqrstvwxyzABCEFGHJKMNPRSTVWXYZ'; break; default: $possible_letters = 'abcdefghijklmnopqrstuvwxyz'; break; } } elseif (!empty($options['captcha_type']) && $options['captcha_type'] == 'numbers') { $possible_letters = '0123456789'; } else { $possible_letters = '0123456789'; } $random_dots = 0; $random_lines = 20; $captcha_text_color = "0x142864"; $captcha_noice_color = "0x142864"; $code = ''; $i = 0; while ($i < $options['total_no_of_characters']) { $code .= substr($possible_letters, mt_rand(0, strlen($possible_letters) - 1), 1); $i++; } $font_size = $image_height * 0.75; $image = @imagecreate($image_width, $image_height); /* setting the background, text and noise colours here */ imagecolorallocate($image, 255, 255, 255); $arr_text_color = self::captcha_hexrgb($captcha_text_color); $text_color = imagecolorallocate( $image, $arr_text_color['red'], $arr_text_color['green'], $arr_text_color['blue'] ); $arr_noice_color = self::captcha_hexrgb($captcha_noice_color); $image_noise_color = imagecolorallocate( $image, $arr_noice_color['red'], $arr_noice_color['green'], $arr_noice_color['blue'] ); /* generating the dots randomly in background */ for ($i = 0; $i < $random_dots; $i++) { imagefilledellipse($image, mt_rand(0, $image_width), mt_rand(0, $image_height), 2, 3, $image_noise_color); } /* generating lines randomly in background of image */ for ($i = 0; $i < $random_lines; $i++) { imageline($image, mt_rand(0, $image_width), mt_rand(0, $image_height), mt_rand(0, $image_width), mt_rand(0, $image_height), $image_noise_color); } /* create a text box and add 6 letters code in it */ $textbox = imagettfbbox($font_size, 0, $font, $code); $x = ($image_width - $textbox[4]) / 2; $y = ($image_height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, (int)$x, (int)$y, $text_color, $font, $code); ob_start(); imagejpeg($image); //showing the image echo ''; imagedestroy($image); //destroying the image instance $_SESSION['captcha_code'] = $code; } // generate_captcha_image static function captcha_hexrgb($hexstr) { $int = hexdec($hexstr); return array( "red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int ); } // captcha_hexrgb static function create_select_options($options, $selected = null, $output = true) { $out = "\n"; foreach ($options as $tmp) { if ((is_array($selected) && in_array($tmp['val'], $selected)) || $selected == $tmp['val']) { $out .= "\n"; } else { $out .= "\n"; } } if ($output) { self::wp_kses_wf($out); } else { return $out; } } // create_select_options static function options_page() { $options = self::get_options(); echo '
'; echo '

WP Captcha PRO

'; echo '
'; echo '
'; wp_nonce_field('wpcatpcha_update_admin_options', 'wpcatpcha_update_admin_options_nonce'); echo ''; $captcha = array(); $captcha[] = array('val' => 'builtin', 'label' => 'Built-in Captcha'); $captcha[] = array('val' => 'icons', 'label' => 'Built-in Icon Captcha', 'class' => 'pro-option'); $captcha[] = array('val' => 'recaptchav2', 'label' => 'Google reCAPTCHA v2', 'class' => 'pro-option'); $captcha[] = array('val' => 'recaptchav3', 'label' => 'Google reCAPTCHA v3', 'class' => 'pro-option'); $captcha[] = array('val' => 'hcaptcha', 'label' => 'hCaptcha', 'class' => 'pro-option'); $captcha[] = array('val' => 'cloudflare', 'label' => 'Cloudflare Turnstile', 'class' => 'pro-option'); echo ''; echo '
'; echo '

' . esc_html__('Display Options', 'captcha-code-authentication') . '

'; submit_button(); echo '
'; echo '
'; echo '
'; echo ''; if (!defined('EPS_REDIRECT_VERSION') && !defined('WF301_PLUGIN_FILE')) { echo ''; } echo ''; echo '
'; echo '
'; echo ' '; echo '
'; } // options_page static function install_wp301() { check_ajax_referer('install_wp301'); if (false === current_user_can('administrator')) { wp_die('Sorry, you have to be an admin to run this action.'); } $plugin_slug = 'eps-301-redirects/eps-301-redirects.php'; $plugin_zip = 'https://downloads.wordpress.org/plugin/eps-301-redirects.latest-stable.zip'; @include_once ABSPATH . 'wp-admin/includes/plugin.php'; @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; @include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; @include_once ABSPATH . 'wp-admin/includes/file.php'; @include_once ABSPATH . 'wp-admin/includes/misc.php'; echo ''; echo '
'; echo 'If things are not done in a minute install the plugin manually via Plugins page

'; echo 'Starting ...

'; wp_cache_flush(); $upgrader = new Plugin_Upgrader(); echo 'Check if WP 301 Redirects is already installed ...
'; if (self::is_plugin_installed($plugin_slug)) { echo 'WP 301 Redirects is already installed!

Making sure it\'s the latest version.
'; $upgrader->upgrade($plugin_slug); $installed = true; } else { echo 'Installing WP 301 Redirects.
'; $installed = $upgrader->install($plugin_zip); } wp_cache_flush(); if (!is_wp_error($installed) && $installed) { echo 'Activating WP 301 Redirects.
'; $activate = activate_plugin($plugin_slug); if (is_null($activate)) { echo 'WP 301 Redirects Activated.
'; echo ''; echo '
If you are not redirected in a few seconds - click here.'; } } else { echo 'Could not install WP 301 Redirects. You\'ll have to download and install manually.'; } echo '
'; } // install_wp301 static function is_plugin_installed($slug) { if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $all_plugins = get_plugins(); if (!empty($all_plugins[$slug])) { return true; } else { return false; } } // is_plugin_installed static function wp_kses_wf($html) { add_filter('safe_style_css', function ($styles) { $styles_wf = array( 'text-align', 'margin', 'color', 'float', 'border', 'background', 'background-color', 'border-bottom', 'border-bottom-color', 'border-bottom-style', 'border-bottom-width', 'border-collapse', 'border-color', 'border-left', 'border-left-color', 'border-left-style', 'border-left-width', 'border-right', 'border-right-color', 'border-right-style', 'border-right-width', 'border-spacing', 'border-style', 'border-top', 'border-top-color', 'border-top-style', 'border-top-width', 'border-width', 'caption-side', 'clear', 'cursor', 'direction', 'font', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'height', 'letter-spacing', 'line-height', 'margin-bottom', 'margin-left', 'margin-right', 'margin-top', 'overflow', 'padding', 'padding-bottom', 'padding-left', 'padding-right', 'padding-top', 'text-decoration', 'text-indent', 'vertical-align', 'width', 'display', ); foreach ($styles_wf as $style_wf) { $styles[] = $style_wf; } return $styles; }); $allowed_tags = wp_kses_allowed_html('post'); $allowed_tags['input'] = array( 'type' => true, 'style' => true, 'class' => true, 'id' => true, 'checked' => true, 'disabled' => true, 'name' => true, 'size' => true, 'placeholder' => true, 'value' => true, 'data-*' => true, 'size' => true, 'disabled' => true ); $allowed_tags['textarea'] = array( 'type' => true, 'style' => true, 'class' => true, 'id' => true, 'checked' => true, 'disabled' => true, 'name' => true, 'size' => true, 'placeholder' => true, 'value' => true, 'data-*' => true, 'cols' => true, 'rows' => true, 'disabled' => true, 'autocomplete' => true ); $allowed_tags['select'] = array( 'type' => true, 'style' => true, 'class' => true, 'id' => true, 'checked' => true, 'disabled' => true, 'name' => true, 'size' => true, 'placeholder' => true, 'value' => true, 'data-*' => true, 'multiple' => true, 'disabled' => true ); $allowed_tags['option'] = array( 'type' => true, 'style' => true, 'class' => true, 'id' => true, 'checked' => true, 'disabled' => true, 'name' => true, 'size' => true, 'placeholder' => true, 'value' => true, 'selected' => true, 'data-*' => true ); $allowed_tags['optgroup'] = array( 'type' => true, 'style' => true, 'class' => true, 'id' => true, 'checked' => true, 'disabled' => true, 'name' => true, 'size' => true, 'placeholder' => true, 'value' => true, 'selected' => true, 'data-*' => true, 'label' => true ); $allowed_tags['a'] = array( 'href' => true, 'data-*' => true, 'class' => true, 'style' => true, 'id' => true, 'target' => true, 'data-*' => true, 'role' => true, 'aria-controls' => true, 'aria-selected' => true, 'disabled' => true ); $allowed_tags['div'] = array( 'style' => true, 'class' => true, 'id' => true, 'data-*' => true, 'role' => true, 'aria-labelledby' => true, 'value' => true, 'aria-modal' => true, 'tabindex' => true ); $allowed_tags['li'] = array( 'style' => true, 'class' => true, 'id' => true, 'data-*' => true, 'role' => true, 'aria-labelledby' => true, 'value' => true, 'aria-modal' => true, 'tabindex' => true ); $allowed_tags['span'] = array( 'style' => true, 'class' => true, 'id' => true, 'data-*' => true, 'aria-hidden' => true ); $allowed_tags['style'] = array( 'class' => true, 'id' => true, 'type' => true, 'style' => true ); $allowed_tags['fieldset'] = array( 'class' => true, 'id' => true, 'type' => true, 'style' => true ); $allowed_tags['link'] = array( 'class' => true, 'id' => true, 'type' => true, 'rel' => true, 'href' => true, 'media' => true, 'style' => true ); $allowed_tags['form'] = array( 'style' => true, 'class' => true, 'id' => true, 'method' => true, 'action' => true, 'data-*' => true, 'style' => true ); $allowed_tags['script'] = array( 'class' => true, 'id' => true, 'type' => true, 'src' => true, 'style' => true ); $allowed_tags['table'] = array( 'class' => true, 'id' => true, 'type' => true, 'cellpadding' => true, 'cellspacing' => true, 'border' => true, 'style' => true ); $allowed_tags['canvas'] = array( 'class' => true, 'id' => true, 'style' => true ); echo wp_kses($html, $allowed_tags); add_filter('safe_style_css', function ($styles) { $styles_wf = array( 'text-align', 'margin', 'color', 'float', 'border', 'background', 'background-color', 'border-bottom', 'border-bottom-color', 'border-bottom-style', 'border-bottom-width', 'border-collapse', 'border-color', 'border-left', 'border-left-color', 'border-left-style', 'border-left-width', 'border-right', 'border-right-color', 'border-right-style', 'border-right-width', 'border-spacing', 'border-style', 'border-top', 'border-top-color', 'border-top-style', 'border-top-width', 'border-width', 'caption-side', 'clear', 'cursor', 'direction', 'font', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'height', 'letter-spacing', 'line-height', 'margin-bottom', 'margin-left', 'margin-right', 'margin-top', 'overflow', 'padding', 'padding-bottom', 'padding-left', 'padding-right', 'padding-top', 'text-decoration', 'text-indent', 'vertical-align', 'width' ); foreach ($styles_wf as $style_wf) { if (($key = array_search($style_wf, $styles)) !== false) { unset($styles[$key]); } } return $styles; }); } // is_plugin_installed } // WP_Captcha_Code add_action('init', array('WP_Captcha_Code', 'init'));