Plugin Directory

Changeset 3334736


Ignore:
Timestamp:
07/27/2025 08:09:53 AM (7 months ago)
Author:
gswebdev
Message:

Add the reCAPTCHA v2 for Contact Form 7 (cf7)

Location:
codenitive-captcha
Files:
18 added
6 edited

Legend:

Unmodified
Added
Removed
  • codenitive-captcha/trunk/codenitive-captcha.php

    r3324092 r3334736  
    33* Plugin Name: Codenitive CAPTCHA Security
    44* Plugin URI:  https://wordpress.org/plugins/codenitive-captcha
    5 * Description: Enhance your website’s security by integrating CAPTCHA verification into essential WordPress and WooCommerce 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.3
     5* 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
    77* Requires at least: 5.6
    88* Requires PHP:      7.4
     
    4040define('CODENITCAPTCHA_PLUGIN_DIR_ASSETS_URL', CODENITCAPTCHA_PLUGIN_DIR_URL.'assets/');
    4141
     42require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-csrf-secret.php';
     43register_activation_hook(__FILE__, ['codenitcaptcha\includes\CODENITCA_Captcha_CSRF', 'activate']);
     44
    4245require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-settings.php';
    4346require_once CODENITCAPTCHA_PLUGIN_DIR_PATH . 'includes/class-captcha-config.php';
     
    5558// Initialize CAPTCHA rendering for comment forms
    5659new \codenitcaptcha\includes\CODENITCA_Comments_Captcha_Render();
     60
     61function 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}
     71add_action( 'plugins_loaded', 'codenitcaptcha_init' );
  • codenitive-captcha/trunk/includes/class-captcha-config.php

    r3321830 r3334736  
    2424    private $comments;
    2525    private $login_show;
     26    private $cf7_forms;
     27
     28    private $csrf_secret = '';
    2629
    2730    private static $script_enqueued = false;
     
    2932
    3033    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 );
    5053        }
    5154       
    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 );
    5360
    5461    }
     
    125132    }
    126133
    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 {
    128139        $return = false;
    129         $active_plugins = apply_filters('active_plugins', get_option( 'active_plugins', array() ));
    130         // Check if WooCommerce is active
    131         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 ) ) {
    132143            $return = true;
    133144        }
     
    138149    public function maybe_enqueue_script() {
    139150        if (!self::$script_enqueued) {
    140             add_action('wp_enqueue_scripts', [$this, 'enqueue_script']);
     151            \add_action('wp_enqueue_scripts', [$this, 'enqueue_script'], 999);
    141152            self::$script_enqueued = true;
    142153        }
    143154    }
    144155
     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
    145166    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
    153187    }
    154188
     
    176210        }
    177211
    178         return apply_filters('codenitcaptcha_messages', $output, $message);
     212        return \apply_filters('codenitcaptcha_messages', $output, $message);
    179213
    180214    }
     
    192226        // Verify nonce first
    193227        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')) {
    195229            return array(
    196230                'status' => 'error',
     
    201235        if(isset($_POST['g-recaptcha-response'])){
    202236           
    203             $response = sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) );
     237            $response = \sanitize_text_field( \wp_unslash( $_POST['g-recaptcha-response'] ) );
    204238
    205239            if (empty($response)) {
     
    214248            if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
    215249                // 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 );
    217251
    218252                // If it's not a valid IP, fall back to empty string
     
    222256            }
    223257
    224             $verify = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
     258            $verify = \wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
    225259                'body' => [
    226260                    'secret' => $secret,
     
    230264            ]);
    231265
    232             if (is_wp_error($verify)) {
     266            if (\is_wp_error($verify)) {
    233267                return array(
    234268                    'status' => 'error',
     
    237271            }
    238272
    239             $result = json_decode(wp_remote_retrieve_body($verify));
     273            $result = \json_decode(\wp_remote_retrieve_body($verify));
    240274
    241275            if (empty($result->success)) {
  • codenitive-captcha/trunk/includes/class-comments-captcha.php

    r3321830 r3334736  
    1616        $this->config = CODENITCA_Recaptcha_Config::get_instance();
    1717       
    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);
    2020    }
    2121
    2222    public function render_recaptcha_html($defaults) {
    2323
    24         if($this->config->get_show_login() != 1 && is_user_logged_in()){
     24        if($this->config->get_show_login() != 1 && \is_user_logged_in()){
    2525            return $defaults;
    2626        }
    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 ){
    2929                return $defaults;
    3030            }
    3131        }
     32
    3233        if($this->config->enable_v2() == 1){
    33             if($this->config->get_wp_comments() == 1){
     34            if($this->config->get_wp_comments() == 1) {
    3435
    3536                $this->config->maybe_enqueue_script();
    3637                $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 );
    3940           
    4041                $defaults['submit_field'] = $captcha . $defaults['submit_field'];
     
    5051        $post_id = $commentdata['comment_post_ID'];
    5152        // Get the post type using the post ID
    52         $post_type = get_post_type($post_id);
     53        $post_type = \get_post_type($post_id);
    5354
    5455        if($this->config->enable_v2() != 1 || empty($site_key) ){
     
    5657        }
    5758
    58         if($this->config->get_show_login() != 1 && is_user_logged_in()) {
     59        if($this->config->get_show_login() != 1 && \is_user_logged_in()) {
    5960            return $commentdata;
    6061        }
     
    6970
    7071        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'),
    7475                ['back_link' => true]
    7576            );   
     
    9091        // Verify nonce first
    9192        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')) {
    9394            return false;
    9495        }
    9596
    9697        $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'])) : '';
    9899
    99100        if (empty($captcha_response) && !empty($_POST)) {
     
    101102        }
    102103
    103         $response = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
     104        $response = \wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
    104105        'body' => [
    105106            'secret' => $secret,
     
    108109        ]);
    109110
    110         if (is_wp_error($response)) {
     111        if (\is_wp_error($response)) {
    111112            return false;
    112113        }
    113114
    114         $body = json_decode(wp_remote_retrieve_body($response), true);
     115        $body = json_decode(\wp_remote_retrieve_body($response), true);
    115116
    116117        return isset($body['success']) && $body['success'];
  • codenitive-captcha/trunk/includes/class-forms.php

    r3324092 r3334736  
    1414    public function __construct() {
    1515        $this->config = CODENITCA_Recaptcha_Config::get_instance();
    16         add_action('init', [$this, 'load_options']);
     16        \add_action('init', [$this, 'load_options']);
    1717    }
    1818
     
    2424
    2525    public function init_v2() {
    26         if(!is_single()){
     26        if(! \is_single()){
    2727            $this->config->maybe_enqueue_script();
    2828        }
    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')){
    3434       
    3535            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);
    3838            }
    3939            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);
    4242            }
    4343            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'));
    4949                }
    5050            }
    5151            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'));
    5454            }
    5555
     
    5757
    5858        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);
    6161        }
    6262
    6363        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);
    6666        }
    6767       
    6868        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);
    7474
    7575    }
     
    7777    public function captcha_style(){
    7878        // 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');
    8181
    8282        // 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; }');
    8484    }
    8585
    8686    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(
    9191                'sitekey' => $this->config->get_site_key_v2()
    9292            ) );
     
    108108    public function display_captcha() {
    109109        if ($this->config->get_site_key_v2()) {
    110             if(function_exists('is_checkout') && is_checkout()){
     110            if( \function_exists('is_checkout') && \is_checkout()){
    111111                $captcha = '<div id="wccn-captcha-box"><div class="g-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div></div>';
    112112            } 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 );
    118118
    119119        }
     
    137137
    138138    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){
    140140            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')) {
    142142                    $validation_errors->add('invalid_nonce', $this->config->messages('nonce_invalid'));
    143143                }
     
    183183        $secret = $this->config->get_secret_key_v2();
    184184        if (empty($secret)) {
    185             wc_add_notice($this->config->messages('config_invalid'), 'error');
     185            \wc_add_notice($this->config->messages('config_invalid'), 'error');
    186186            return;
    187187        }
    188188
    189189        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');
    192192            return;
    193193        }
    194194
    195195        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');
    197197            return;
    198198        }
    199199
    200         $response = sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) );
     200        $response = \sanitize_text_field( \wp_unslash( $_POST['g-recaptcha-response'] ) );
    201201       
    202202        $remoteip = '';
     
    209209        }
    210210
    211         $verify = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
     211        $verify = \wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
    212212            'body' => [
    213213                'secret' => $secret,
     
    217217        ]);
    218218
    219         $result = json_decode(wp_remote_retrieve_body($verify));
     219        $result = json_decode(\wp_remote_retrieve_body($verify));
    220220
    221221        if (empty($result->success)) {
    222             wc_add_notice($this->config->messages('captcha_invalid'), 'error');
     222            \wc_add_notice($this->config->messages('captcha_invalid'), 'error');
    223223        }
    224224    }
    225225
    226226    public function add_checkout_recaptcha_script() {
    227         if (!is_checkout()) return;
     227        if (! \is_checkout()) return;
    228228        ?>
    229229        <div id="recaptcha-script-placeholder"></div>
  • codenitive-captcha/trunk/includes/class-settings.php

    r3321830 r3334736  
    2727        // Check if WooCommerce is active
    2828        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 ) ) {
    2940            $return = true;
    3041        }
     
    8798        add_settings_section('codenitcaptcha_wp_options_section', '<h3>WordPress Options</h3><hr>', null, 'codenitcaptcha_options');
    8899       
     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
    89104        if (self::check_active_woo()) {
    90105            add_settings_section('codenitcaptcha_woo_options_section', '<h3>Woocommerce Options</h3><hr>', null, 'codenitcaptcha_options');
     
    204219            '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.'
    205220        ]);
     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        }
    206233
    207234        self::codenitcaptcha_register_field([
  • codenitive-captcha/trunk/readme.txt

    r3324092 r3334736  
    11=== Codenitive CAPTCHA Security ===
    22Contributors: gswebdev
    3 Tags: google recaptcha, wordpress captcha, spam protection, woocommerce security
     3Tags: google recaptcha, wordpress captcha, woocommerce security, Contact form 7 (cf7)
    44Requires at least: 5.6
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 1.0.3
     7Stable tag: 1.0.4
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Protect your WordPress and WooCommerce login, registration, and checkout forms with lightweight Google reCAPTCHA v2.
     11Protect your WordPress and WooCommerce login, registration, and checkout Contact form 7 (cf7) forms with lightweight Google reCAPTCHA v2.
    1212
    1313== Description ==
    1414
    15 Enhance your websites security by integrating CAPTCHA verification into essential WordPress and WooCommerce forms. Google reCAPTCHA By Codenitive helps prevent spam, bot abuse, and unauthorized access by adding **Google reCAPTCHA** (v2) to critical forms:
     15Enhance 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:
    1616
    1717* WordPress Login
     
    2020* WooCommerce Login, Registration, Checkout
    2121* 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)
    2423
    2524== Features ==
     
    2827  * WordPress Login, Registration, Lost Password, Comment form
    2928  * WooCommerce Login, Registration, Checkout and Product Comment form
     29  * Contact form 7 (cf7)
    30301. Hide captcha for login users
    31311. Prevent spam, bots, and brute-force attacks
     
    7777Yes! It supports login, registration, and checkout forms in WooCommerce.
    7878
    79 = Will it slow down my site? =
     79= Does this plugin work with Contact form 7? =
    8080
    81 No. The plugin is lightweight and optimized to only load CAPTCHA scripts on pages where needed.
     81Yes,
     82
     831. Go to **Settings → Codenitive Captcha**
     841. Open the Options tab
     851. Enable the Contact Form 7 checkbox
     861. and add the shortcode [codenit_recaptcha] in the contact form 7
     871. Save settings — reCAPTCHA will now appear on your form
    8288
    8389= Can I customize where CAPTCHA appears? =
     
    95101
    96102== Coming Next ==
    97 - Contact Form 7 reCAPTCHA support
    98103- Google reCAPTCHA v3 support
    99104
     
    113118* Rename plugin to reCAPTCHA By Codenitive
    114119
     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
    115126== Upgrade Notice ==
    116127
     
    121132* Rename plugin to reCAPTCHA By Codenitive
    122133
     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
    123140== Feedback ==
    124141
Note: See TracChangeset for help on using the changeset viewer.