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') . '
' . esc_html__('Options saved.', 'captcha-code-authentication') . '
'; 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 '
 . ')