Changeset 3334736
- Timestamp:
- 07/27/2025 08:09:53 AM (7 months ago)
- Location:
- codenitive-captcha
- Files:
-
- 18 added
- 6 edited
-
tags/1.0.4 (added)
-
tags/1.0.4/assets (added)
-
tags/1.0.4/assets/js (added)
-
tags/1.0.4/assets/js/checkout.js (added)
-
tags/1.0.4/assets/js/scripts.js (added)
-
tags/1.0.4/codenitive-captcha.php (added)
-
tags/1.0.4/includes (added)
-
tags/1.0.4/includes/class-captcha-config.php (added)
-
tags/1.0.4/includes/class-cf7-captcha.php (added)
-
tags/1.0.4/includes/class-comments-captcha.php (added)
-
tags/1.0.4/includes/class-csrf-secret.php (added)
-
tags/1.0.4/includes/class-forms.php (added)
-
tags/1.0.4/includes/class-settings.php (added)
-
tags/1.0.4/index.php (added)
-
tags/1.0.4/readme.txt (added)
-
trunk/assets/js/scripts.js (added)
-
trunk/codenitive-captcha.php (modified) (3 diffs)
-
trunk/includes/class-captcha-config.php (modified) (11 diffs)
-
trunk/includes/class-cf7-captcha.php (added)
-
trunk/includes/class-comments-captcha.php (modified) (7 diffs)
-
trunk/includes/class-csrf-secret.php (added)
-
trunk/includes/class-forms.php (modified) (9 diffs)
-
trunk/includes/class-settings.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
codenitive-captcha/trunk/codenitive-captcha.php
r3324092 r3334736 3 3 * Plugin Name: Codenitive CAPTCHA Security 4 4 * Plugin URI: https://wordpress.org/plugins/codenitive-captcha 5 * Description: Enhance your website’s security by integrating CAPTCHA verification into essential WordPress and WooCommerceforms. This plugin helps prevent spam, bots, and unauthorized access by adding CAPTCHA challenges to key areas such as login, registration, password reset, checkout, and more. With built-in support for Google reCAPTCHA (v2), this plugin provides a seamless way to protect both the WordPress core and WooCommerce without disrupting the user experience.6 * Version: 1.0. 35 * Description: Enhance your website’s security by integrating CAPTCHA verification into essential WordPress, WooCommerce, Contact form 7 (cf7) forms. This plugin helps prevent spam, bots, and unauthorized access by adding CAPTCHA challenges to key areas such as login, registration, password reset, checkout, and more. With built-in support for Google reCAPTCHA (v2), this plugin provides a seamless way to protect both the WordPress core and WooCommerce without disrupting the user experience. 6 * Version: 1.0.4 7 7 * Requires at least: 5.6 8 8 * Requires PHP: 7.4 … … 40 40 define('CODENITCAPTCHA_PLUGIN_DIR_ASSETS_URL', CODENITCAPTCHA_PLUGIN_DIR_URL.'assets/'); 41 41 42 require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-csrf-secret.php'; 43 register_activation_hook(__FILE__, ['codenitcaptcha\includes\CODENITCA_Captcha_CSRF', 'activate']); 44 42 45 require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-settings.php'; 43 46 require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-captcha-config.php'; … … 55 58 // Initialize CAPTCHA rendering for comment forms 56 59 new \codenitcaptcha\includes\CODENITCA_Comments_Captcha_Render(); 60 61 function codenitcaptcha_init() { 62 63 if( class_exists( 'WPCF7' ) ) { 64 // Load CAPTCHA for Contact Form 7 forms 65 require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-cf7-captcha.php'; 66 // Initialize CAPTCHA rendering for Contact Form 7 67 \codenitcaptcha\includes\CODENITCA_Captcha_CF7_Render::get_instance(); 68 } 69 70 } 71 add_action( 'plugins_loaded', 'codenitcaptcha_init' ); -
codenitive-captcha/trunk/includes/class-captcha-config.php
r3321830 r3334736 24 24 private $comments; 25 25 private $login_show; 26 private $cf7_forms; 27 28 private $csrf_secret = ''; 26 29 27 30 private static $script_enqueued = false; … … 29 32 30 33 private function __construct() { 31 $this->enable_v2 = get_option('codenitcaptcha_v2_status');32 $this->enable_v3 = get_option('codenitcaptcha_v3_status');33 34 $this->site_key_v2 = esc_attr(get_option('codenitcaptcha_site_key') );35 $this->secret_key_v2 = esc_attr(get_option('codenitcaptcha_secret_key') );36 $this->site_key_v3 = esc_attr(get_option('codenitcaptcha_site_v3_key') );37 $this->secret_key_v3 = esc_attr(get_option('codenitcaptcha_secret_v3_key') );38 39 $this->wp_login = get_option( 'codenitcaptcha_wp_login', 0 );40 $this->wp_register = get_option('codenitcaptcha_wp_register', 0);41 $this->wp_forgetpass = get_option('codenitcaptcha_wp_forget_pass', 0);42 $this->wp_comments = get_option('codenitcaptcha_wp_comments', 0);43 44 if($this->check_active_ woo()){45 $this->register = get_option( 'codenitcaptcha_woo_register', 0 );46 $this->login = get_option( 'codenitcaptcha_woo_login', 0 );47 $this->checkout = get_option( 'codenitcaptcha_woo_checkout', 0 );48 $this->forgetpass = get_option( 'codenitcaptcha_woo_forgetpass', 0 );49 $this->comments = get_option( 'codenitcaptcha_woo_comments', 0 );34 $this->enable_v2 = \get_option('codenitcaptcha_v2_status'); 35 $this->enable_v3 = \get_option('codenitcaptcha_v3_status'); 36 37 $this->site_key_v2 = \esc_attr( \get_option('codenitcaptcha_site_key') ); 38 $this->secret_key_v2 = \esc_attr( \get_option('codenitcaptcha_secret_key') ); 39 $this->site_key_v3 = \esc_attr( \get_option('codenitcaptcha_site_v3_key') ); 40 $this->secret_key_v3 = \esc_attr( \get_option('codenitcaptcha_secret_v3_key') ); 41 42 $this->wp_login = \get_option( 'codenitcaptcha_wp_login', 0 ); 43 $this->wp_register = \get_option('codenitcaptcha_wp_register', 0); 44 $this->wp_forgetpass = \get_option('codenitcaptcha_wp_forget_pass', 0); 45 $this->wp_comments = \get_option('codenitcaptcha_wp_comments', 0); 46 47 if($this->check_active_plugin('woocommerce/woocommerce.php')){ 48 $this->register = \get_option( 'codenitcaptcha_woo_register', 0 ); 49 $this->login = \get_option( 'codenitcaptcha_woo_login', 0 ); 50 $this->checkout = \get_option( 'codenitcaptcha_woo_checkout', 0 ); 51 $this->forgetpass = \get_option( 'codenitcaptcha_woo_forgetpass', 0 ); 52 $this->comments = \get_option( 'codenitcaptcha_woo_comments', 0 ); 50 53 } 51 54 52 $this->login_show = get_option( 'codenitcaptcha_hide_login', 0 ); 55 if($this->check_active_plugin('contact-form-7/wp-contact-form-7.php')){ 56 $this->cf7_forms = \get_option('codenitcaptcha_cf7_forms', 0); 57 } 58 59 $this->login_show = \get_option( 'codenitcaptcha_hide_login', 0 ); 53 60 54 61 } … … 125 132 } 126 133 127 public function check_active_woo(): bool { 134 public function get_cf7_option(): int { 135 return $this->cf7_forms; 136 } 137 138 public function check_active_plugin($root): bool { 128 139 $return = false; 129 $active_plugins = apply_filters('active_plugins',get_option( 'active_plugins', array() ));130 // Check if WooCommerceis active131 if ( in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) {140 $active_plugins = \apply_filters('active_plugins', \get_option( 'active_plugins', array() )); 141 // Check if plugin is active 142 if ( in_array( $root, $active_plugins ) ) { 132 143 $return = true; 133 144 } … … 138 149 public function maybe_enqueue_script() { 139 150 if (!self::$script_enqueued) { 140 add_action('wp_enqueue_scripts', [$this, 'enqueue_script']);151 \add_action('wp_enqueue_scripts', [$this, 'enqueue_script'], 999); 141 152 self::$script_enqueued = true; 142 153 } 143 154 } 144 155 156 // public function enqueue_script() { 157 // \wp_enqueue_script( 158 // 'google-recaptcha', 159 // 'https://www.google.com/recaptcha/api.js', 160 // [], 161 // '10.0.6', 162 // true 163 // ); 164 // } 165 145 166 public function enqueue_script() { 146 wp_enqueue_script( 147 'google-recaptcha', 148 'https://www.google.com/recaptcha/api.js', 149 [], 150 CODENITCAPTCHA_VERSION, 151 true 152 ); 167 if ($this->get_site_key_v2() && !is_admin()) { 168 169 $source = 'google.com'; 170 $url = \sprintf( 'https://www.%s/recaptcha/api.js', $source ); 171 172 $url = \add_query_arg( array( 173 //'hl' => esc_attr( \apply_filters( 'wpcf7_recaptcha_locale', \get_locale() ) ), // Lowercase L 174 'onload' => 'recaptchaCallback', 175 'render' => 'explicit', 176 ), $url ); 177 178 \wp_enqueue_script( 'codenitcaptcha-recaptcha-js', CODENITCAPTCHA_PLUGIN_DIR_URL . 'assets/js/scripts.js', array(), '1.0.4', true ); 179 \wp_enqueue_script( 'google-recaptcha', $url, array( 'codenitcaptcha-recaptcha-js' ), CODENITCAPTCHA_VERSION, true ); 180 181 wp_localize_script('codenitcaptcha-recaptcha-js', 'CodenitCaptchaData', [ 182 'siteKey' => $this->get_site_key_v2(), 183 ]); 184 185 } 186 153 187 } 154 188 … … 176 210 } 177 211 178 return apply_filters('codenitcaptcha_messages', $output, $message);212 return \apply_filters('codenitcaptcha_messages', $output, $message); 179 213 180 214 } … … 192 226 // Verify nonce first 193 227 if (!isset($_POST['codenitcaptcha_nonce']) || 194 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {228 !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) { 195 229 return array( 196 230 'status' => 'error', … … 201 235 if(isset($_POST['g-recaptcha-response'])){ 202 236 203 $response = sanitize_text_field(wp_unslash( $_POST['g-recaptcha-response'] ) );237 $response = \sanitize_text_field( \wp_unslash( $_POST['g-recaptcha-response'] ) ); 204 238 205 239 if (empty($response)) { … … 214 248 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { 215 249 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash 216 $remoteip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP );250 $remoteip = \filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); 217 251 218 252 // If it's not a valid IP, fall back to empty string … … 222 256 } 223 257 224 $verify = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [258 $verify = \wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [ 225 259 'body' => [ 226 260 'secret' => $secret, … … 230 264 ]); 231 265 232 if ( is_wp_error($verify)) {266 if (\is_wp_error($verify)) { 233 267 return array( 234 268 'status' => 'error', … … 237 271 } 238 272 239 $result = json_decode(wp_remote_retrieve_body($verify));273 $result = \json_decode(\wp_remote_retrieve_body($verify)); 240 274 241 275 if (empty($result->success)) { -
codenitive-captcha/trunk/includes/class-comments-captcha.php
r3321830 r3334736 16 16 $this->config = CODENITCA_Recaptcha_Config::get_instance(); 17 17 18 add_filter('comment_form_defaults', [$this, 'render_recaptcha_html'], 50, 1);19 add_filter('preprocess_comment', [$this, 'comment_captcha_validate'], 10, 1);18 \add_filter('comment_form_defaults', [$this, 'render_recaptcha_html'], 50, 1); 19 \add_filter('preprocess_comment', [$this, 'comment_captcha_validate'], 10, 1); 20 20 } 21 21 22 22 public function render_recaptcha_html($defaults) { 23 23 24 if($this->config->get_show_login() != 1 && is_user_logged_in()){24 if($this->config->get_show_login() != 1 && \is_user_logged_in()){ 25 25 return $defaults; 26 26 } 27 if( function_exists('is_product')){28 if( is_product() && $this->config->get_wcc_comments() == 1 ){27 if(\function_exists('is_product')){ 28 if( \is_product() && $this->config->get_wcc_comments() == 1 ){ 29 29 return $defaults; 30 30 } 31 31 } 32 32 33 if($this->config->enable_v2() == 1){ 33 if($this->config->get_wp_comments() == 1) {34 if($this->config->get_wp_comments() == 1) { 34 35 35 36 $this->config->maybe_enqueue_script(); 36 37 $site_key = $this->config->get_site_key_v2(); 37 $captcha = '<div class="g-recaptcha" data-sitekey="' .esc_attr($site_key) . '"></div>';38 $captcha .= wp_nonce_field( 'codenitcaptcha_action', 'codenitcaptcha_nonce', true, false );38 $captcha = '<div id="codenitcaptcha-comments-recaptcha" class="g-recaptcha" data-sitekey="' . \esc_attr($site_key) . '"></div>'; 39 $captcha .= \wp_nonce_field( 'codenitcaptcha_action', 'codenitcaptcha_nonce', true, false ); 39 40 40 41 $defaults['submit_field'] = $captcha . $defaults['submit_field']; … … 50 51 $post_id = $commentdata['comment_post_ID']; 51 52 // Get the post type using the post ID 52 $post_type = get_post_type($post_id);53 $post_type = \get_post_type($post_id); 53 54 54 55 if($this->config->enable_v2() != 1 || empty($site_key) ){ … … 56 57 } 57 58 58 if($this->config->get_show_login() != 1 && is_user_logged_in()) {59 if($this->config->get_show_login() != 1 && \is_user_logged_in()) { 59 60 return $commentdata; 60 61 } … … 69 70 70 71 if(!$this->verify_captcha()) { 71 wp_die(72 wp_kses_post($this->config->messages('captcha_invalid')),73 esc_html__('reCAPTCHA Failed', 'codenitive-captcha'),72 \wp_die( 73 \wp_kses_post($this->config->messages('captcha_invalid')), 74 \esc_html__('reCAPTCHA Failed', 'codenitive-captcha'), 74 75 ['back_link' => true] 75 76 ); … … 90 91 // Verify nonce first 91 92 if (!isset($_POST['codenitcaptcha_nonce']) || 92 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {93 ! \wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) { 93 94 return false; 94 95 } 95 96 96 97 $captcha_response = ''; 97 $captcha_response = isset($_POST['g-recaptcha-response']) ? sanitize_text_field(wp_unslash($_POST['g-recaptcha-response'])) : '';98 $captcha_response = isset($_POST['g-recaptcha-response']) ? \sanitize_text_field(\wp_unslash($_POST['g-recaptcha-response'])) : ''; 98 99 99 100 if (empty($captcha_response) && !empty($_POST)) { … … 101 102 } 102 103 103 $response = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [104 $response = \wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [ 104 105 'body' => [ 105 106 'secret' => $secret, … … 108 109 ]); 109 110 110 if ( is_wp_error($response)) {111 if (\is_wp_error($response)) { 111 112 return false; 112 113 } 113 114 114 $body = json_decode( wp_remote_retrieve_body($response), true);115 $body = json_decode(\wp_remote_retrieve_body($response), true); 115 116 116 117 return isset($body['success']) && $body['success']; -
codenitive-captcha/trunk/includes/class-forms.php
r3324092 r3334736 14 14 public function __construct() { 15 15 $this->config = CODENITCA_Recaptcha_Config::get_instance(); 16 add_action('init', [$this, 'load_options']);16 \add_action('init', [$this, 'load_options']); 17 17 } 18 18 … … 24 24 25 25 public function init_v2() { 26 if(! is_single()){26 if(! \is_single()){ 27 27 $this->config->maybe_enqueue_script(); 28 28 } 29 add_action('login_enqueue_scripts', array($this->config, 'enqueue_script'));30 add_action('login_enqueue_scripts', array($this, 'captcha_style'));31 add_action('wp_enqueue_scripts', array($this, 'captcha_style'));32 33 if ($this->config->check_active_woo()){29 \add_action('login_enqueue_scripts', array($this->config, 'enqueue_script')); 30 \add_action('login_enqueue_scripts', array($this, 'captcha_style')); 31 \add_action('wp_enqueue_scripts', array($this, 'captcha_style')); 32 33 if($this->config->check_active_plugin('woocommerce/woocommerce.php')){ 34 34 35 35 if ( $this->config->get_wcc_register() == 1 ) { 36 add_action('woocommerce_register_form', array($this, 'display_captcha'), 20);37 add_filter('woocommerce_process_registration_errors', array($this, 'validate_registration_captcha'), 5, 4);36 \add_action('woocommerce_register_form', array($this, 'display_captcha'), 20); 37 \add_filter('woocommerce_process_registration_errors', array($this, 'validate_registration_captcha'), 5, 4); 38 38 } 39 39 if ( $this->config->get_wcc_login() == 1 ) { 40 add_action('woocommerce_login_form', array($this, 'display_captcha'), 30);41 add_filter('woocommerce_process_login_errors', array($this, 'validate_login_captcha'), 10, 3);40 \add_action('woocommerce_login_form', array($this, 'display_captcha'), 30); 41 \add_filter('woocommerce_process_login_errors', array($this, 'validate_login_captcha'), 10, 3); 42 42 } 43 43 if ( $this->config->get_wcc_checkout() == 1 ) { 44 if(! is_user_logged_in() || ($this->config->get_show_login() == 1 &&is_user_logged_in())){45 add_action('woocommerce_review_order_before_submit', array($this, 'display_captcha'), 20);46 add_action('woocommerce_checkout_process', array($this, 'validate_checkout_captcha'), 10);47 add_action('wp_footer', array($this, 'add_checkout_recaptcha_script'), 99);48 add_action('wp_enqueue_scripts', array($this, 'captcha_checkout_script'));44 if(! \is_user_logged_in() || ($this->config->get_show_login() == 1 && \is_user_logged_in())){ 45 \add_action('woocommerce_review_order_before_submit', array($this, 'display_captcha'), 20); 46 \add_action('woocommerce_checkout_process', array($this, 'validate_checkout_captcha'), 10); 47 \add_action('wp_footer', array($this, 'add_checkout_recaptcha_script'), 99); 48 \add_action('wp_enqueue_scripts', array($this, 'captcha_checkout_script')); 49 49 } 50 50 } 51 51 if ( $this->config->get_wcc_forgetpass() == 1 ) { 52 add_action('woocommerce_lostpassword_form', array($this, 'display_captcha'), 20);53 add_action('woocommerce_lostpassword_form', array($this, 'wc_forgot_password_hidden_field'));52 \add_action('woocommerce_lostpassword_form', array($this, 'display_captcha'), 20); 53 \add_action('woocommerce_lostpassword_form', array($this, 'wc_forgot_password_hidden_field')); 54 54 } 55 55 … … 57 57 58 58 if ( $this->config->get_wp_login() == 1 ) { 59 add_action('login_form', array($this, 'display_captcha'), 20);60 add_action('authenticate', array($this, 'validate_wplogin_captcha'), 21, 3);59 \add_action('login_form', array($this, 'display_captcha'), 20); 60 \add_action('authenticate', array($this, 'validate_wplogin_captcha'), 21, 3); 61 61 } 62 62 63 63 if ( $this->config->get_wp_register() == 1 ) { 64 add_action('register_form', array($this, 'display_captcha'), 20);65 add_action('registration_errors', array($this, 'validate_wpregister_captcha'), 21, 3);64 \add_action('register_form', array($this, 'display_captcha'), 20); 65 \add_action('registration_errors', array($this, 'validate_wpregister_captcha'), 21, 3); 66 66 } 67 67 68 68 if ( $this->config->get_wp_forgetpass() == 1 ) { 69 add_action('lostpassword_form', array($this, 'display_captcha'), 20);70 add_action('lostpassword_form', array($this, 'wp_forgot_password_hidden_field'));71 } 72 73 add_action('lostpassword_post', array($this, 'validate_forgetpass_captcha'), 21, 3);69 \add_action('lostpassword_form', array($this, 'display_captcha'), 20); 70 \add_action('lostpassword_form', array($this, 'wp_forgot_password_hidden_field')); 71 } 72 73 \add_action('lostpassword_post', array($this, 'validate_forgetpass_captcha'), 21, 3); 74 74 75 75 } … … 77 77 public function captcha_style(){ 78 78 // Register your own empty CSS file (optional) or attach to one you know is enqueued 79 wp_register_style('codenitcaptcha-style', false, array(), '1.0.3');80 wp_enqueue_style('codenitcaptcha-style');79 \wp_register_style('codenitcaptcha-style', false, array(), '1.0.4'); 80 \wp_enqueue_style('codenitcaptcha-style'); 81 81 82 82 // Add your inline CSS to that handle 83 wp_add_inline_style('codenitcaptcha-style', '.g-recaptcha { margin-bottom: 15px; }');83 \wp_add_inline_style('codenitcaptcha-style', '.g-recaptcha { margin-bottom: 15px; }'); 84 84 } 85 85 86 86 public function captcha_checkout_script(){ 87 if( function_exists('is_checkout') && is_checkout()){88 wp_register_script( 'codenitcaptcha-script-checkout', CODENITCAPTCHA_PLUGIN_DIR_ASSETS_URL.'js/checkout.js', array(), 0.00002, true );89 wp_enqueue_script( 'codenitcaptcha-script-checkout' );90 wp_localize_script( 'codenitcaptcha-script-checkout', 'codenitcaptcha_captcha_obj', array(87 if( \function_exists('is_checkout') && \is_checkout()) { 88 \wp_register_script( 'codenitcaptcha-script-checkout', CODENITCAPTCHA_PLUGIN_DIR_ASSETS_URL.'js/checkout.js', array(), 0.00002, true ); 89 \wp_enqueue_script( 'codenitcaptcha-script-checkout' ); 90 \wp_localize_script( 'codenitcaptcha-script-checkout', 'codenitcaptcha_captcha_obj', array( 91 91 'sitekey' => $this->config->get_site_key_v2() 92 92 ) ); … … 108 108 public function display_captcha() { 109 109 if ($this->config->get_site_key_v2()) { 110 if( function_exists('is_checkout') &&is_checkout()){110 if( \function_exists('is_checkout') && \is_checkout()){ 111 111 $captcha = '<div id="wccn-captcha-box"><div class="g-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div></div>'; 112 112 } else { 113 $captcha = '<div class="g-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';114 } 115 116 echo wp_kses_post(wp_nonce_field( 'codenitcaptcha_action', 'codenitcaptcha_nonce' ));117 echo wp_kses_post( $captcha );113 $captcha = '<div id="codenitcaptcha-comments-recaptcha" class="g-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>'; 114 } 115 116 echo \wp_kses_post( \wp_nonce_field( 'codenitcaptcha_action', 'codenitcaptcha_nonce' )); 117 echo \wp_kses_post( $captcha ); 118 118 119 119 } … … 137 137 138 138 public function validate_forgetpass_captcha($validation_errors, $user_data = '') { 139 if( $this->config->check_active_woo() && $this->config->get_wcc_forgetpass() == 1){139 if( $this->config->check_active_plugin('woocommerce/woocommerce.php') && $this->config->get_wcc_forgetpass() == 1){ 140 140 if(isset($_POST['wc_forget']) && $_POST['wc_forget'] == 'wc'){ 141 if (!isset($_POST['woocommerce-lost-password-nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['woocommerce-lost-password-nonce'])), 'lost_password')) {141 if (!isset($_POST['woocommerce-lost-password-nonce']) || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash($_POST['woocommerce-lost-password-nonce'])), 'lost_password')) { 142 142 $validation_errors->add('invalid_nonce', $this->config->messages('nonce_invalid')); 143 143 } … … 183 183 $secret = $this->config->get_secret_key_v2(); 184 184 if (empty($secret)) { 185 wc_add_notice($this->config->messages('config_invalid'), 'error');185 \wc_add_notice($this->config->messages('config_invalid'), 'error'); 186 186 return; 187 187 } 188 188 189 189 if (!isset($_POST['codenitcaptcha_nonce']) || 190 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {191 wc_add_notice($this->config->messages('nonce_invalid'), 'error');190 ! \wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) { 191 \wc_add_notice($this->config->messages('nonce_invalid'), 'error'); 192 192 return; 193 193 } 194 194 195 195 if (empty($_POST['g-recaptcha-response'])) { 196 wc_add_notice($this->config->messages('captcha_required'), 'error');196 \wc_add_notice($this->config->messages('captcha_required'), 'error'); 197 197 return; 198 198 } 199 199 200 $response = sanitize_text_field(wp_unslash( $_POST['g-recaptcha-response'] ) );200 $response = \sanitize_text_field( \wp_unslash( $_POST['g-recaptcha-response'] ) ); 201 201 202 202 $remoteip = ''; … … 209 209 } 210 210 211 $verify = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [211 $verify = \wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [ 212 212 'body' => [ 213 213 'secret' => $secret, … … 217 217 ]); 218 218 219 $result = json_decode( wp_remote_retrieve_body($verify));219 $result = json_decode(\wp_remote_retrieve_body($verify)); 220 220 221 221 if (empty($result->success)) { 222 wc_add_notice($this->config->messages('captcha_invalid'), 'error');222 \wc_add_notice($this->config->messages('captcha_invalid'), 'error'); 223 223 } 224 224 } 225 225 226 226 public function add_checkout_recaptcha_script() { 227 if (! is_checkout()) return;227 if (! \is_checkout()) return; 228 228 ?> 229 229 <div id="recaptcha-script-placeholder"></div> -
codenitive-captcha/trunk/includes/class-settings.php
r3321830 r3334736 27 27 // Check if WooCommerce is active 28 28 if ( in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) { 29 $return = true; 30 } 31 32 return $return; 33 } 34 35 public static function check_active_cf7(): bool { 36 $return = false; 37 $active_plugins = get_option( 'active_plugins', array() ); 38 // Check if WooCommerce is active 39 if ( in_array( 'contact-form-7/wp-contact-form-7.php', $active_plugins ) ) { 29 40 $return = true; 30 41 } … … 87 98 add_settings_section('codenitcaptcha_wp_options_section', '<h3>WordPress Options</h3><hr>', null, 'codenitcaptcha_options'); 88 99 100 if (self::check_active_cf7()) { 101 add_settings_section('codenitcaptcha_wp_options_section', '<h3>Contact Form 7 reCaptcha Options</h3><hr>', null, 'codenitcaptcha_cf7_recaptcha'); 102 } 103 89 104 if (self::check_active_woo()) { 90 105 add_settings_section('codenitcaptcha_woo_options_section', '<h3>Woocommerce Options</h3><hr>', null, 'codenitcaptcha_options'); … … 204 219 'description' => 'Check to enable the captcha in all post types comment forms including Woocommerce Products. To hide the captcha from Product Comment form check the `Hide from Product Comment Form` option inside the Woocommerce options.' 205 220 ]); 221 222 if (self::check_active_cf7()) { 223 self::codenitcaptcha_register_field([ 224 'option_group' => 'codenitcaptcha_options', 225 'option_name' => 'codenitcaptcha_cf7_forms', 226 'field_label' => 'Contact Form 7', 227 'field_type' => 'checkbox', 228 'page' => 'codenitcaptcha_options', 229 'section' => 'codenitcaptcha_wp_options_section', 230 'description' => 'Check this option and add the [codenit_recaptcha] shortcode in the contact form 7.' 231 ]); 232 } 206 233 207 234 self::codenitcaptcha_register_field([ -
codenitive-captcha/trunk/readme.txt
r3324092 r3334736 1 1 === Codenitive CAPTCHA Security === 2 2 Contributors: gswebdev 3 Tags: google recaptcha, wordpress captcha, spam protection, woocommerce security3 Tags: google recaptcha, wordpress captcha, woocommerce security, Contact form 7 (cf7) 4 4 Requires at least: 5.6 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.4 7 Stable tag: 1.0. 37 Stable tag: 1.0.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Protect your WordPress and WooCommerce login, registration, and checkout forms with lightweight Google reCAPTCHA v2.11 Protect your WordPress and WooCommerce login, registration, and checkout Contact form 7 (cf7) forms with lightweight Google reCAPTCHA v2. 12 12 13 13 == Description == 14 14 15 Enhance your websites security by integrating CAPTCHA verification into essential WordPress and WooCommerceforms. Google reCAPTCHA By Codenitive helps prevent spam, bot abuse, and unauthorized access by adding **Google reCAPTCHA** (v2) to critical forms:15 Enhance your websites security by integrating CAPTCHA verification into essential WordPress WooCommerce and Contact form 7 forms. Google reCAPTCHA By Codenitive helps prevent spam, bot abuse, and unauthorized access by adding **Google reCAPTCHA** (v2) to critical forms: 16 16 17 17 * WordPress Login … … 20 20 * WooCommerce Login, Registration, Checkout 21 21 * Comments form 22 23 Built for performance and ease of use, Codenitive CAPTCHA Security requires no coding and integrates smoothly with your site's design. 22 * Contact form 7 (cf7) 24 23 25 24 == Features == … … 28 27 * WordPress Login, Registration, Lost Password, Comment form 29 28 * WooCommerce Login, Registration, Checkout and Product Comment form 29 * Contact form 7 (cf7) 30 30 1. Hide captcha for login users 31 31 1. Prevent spam, bots, and brute-force attacks … … 77 77 Yes! It supports login, registration, and checkout forms in WooCommerce. 78 78 79 = Will it slow down my site? =79 = Does this plugin work with Contact form 7? = 80 80 81 No. The plugin is lightweight and optimized to only load CAPTCHA scripts on pages where needed. 81 Yes, 82 83 1. Go to **Settings → Codenitive Captcha** 84 1. Open the Options tab 85 1. Enable the Contact Form 7 checkbox 86 1. and add the shortcode [codenit_recaptcha] in the contact form 7 87 1. Save settings — reCAPTCHA will now appear on your form 82 88 83 89 = Can I customize where CAPTCHA appears? = … … 95 101 96 102 == Coming Next == 97 - Contact Form 7 reCAPTCHA support98 103 - Google reCAPTCHA v3 support 99 104 … … 113 118 * Rename plugin to reCAPTCHA By Codenitive 114 119 120 = 1.0.3 = 121 * Rename plugin to Codenitive CAPTCHA Security 122 123 = 1.0.4 = 124 * Add reCAPTCHA security for Contact form 7 (cf7) 125 115 126 == Upgrade Notice == 116 127 … … 121 132 * Rename plugin to reCAPTCHA By Codenitive 122 133 134 = 1.0.3 = 135 * Rename plugin to Codenitive CAPTCHA Security 136 137 = 1.0.4 = 138 * Add reCAPTCHA security for Contact form 7 (cf7) 139 123 140 == Feedback == 124 141
Note: See TracChangeset
for help on using the changeset viewer.