Plugin Directory

Changeset 3334966


Ignore:
Timestamp:
07/27/2025 05:52:40 PM (8 months ago)
Author:
gswebdev
Message:

Fixed the duplicate id issue in the WooCommerce my account page Login and Register forms

Location:
codenitive-captcha
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • codenitive-captcha/tags/1.0.4/assets/js/scripts.js

    r3334736 r3334966  
    4242            }
    4343        }
     44       
     45        const siteKey = CodenitCaptchaData?.siteKey;
    4446
    45         const siteKey = CodenitCaptchaData?.siteKey;
     47        if (siteKey) {
     48            const elements = document.querySelectorAll('.codenitcaptcha-recaptcha');
     49       
     50            elements.forEach((element) => {
     51                grecaptcha.render(element, {
     52                    sitekey: siteKey
     53                });
     54            });
     55        }
    4656
    47         if (siteKey && document.getElementById('codenitcaptcha-comments-recaptcha')) {
    48             grecaptcha.render('codenitcaptcha-comments-recaptcha', {
    49                 sitekey: siteKey
    50             });
    51         }
    5257
    5358    };
  • codenitive-captcha/tags/1.0.4/includes/class-captcha-config.php

    r3334736 r3334966  
    176176            ), $url );
    177177
    178             \wp_enqueue_script( 'codenitcaptcha-recaptcha-js', CODENITCAPTCHA_PLUGIN_DIR_URL . 'assets/js/scripts.js', array(), '1.0.4', true );
     178            \wp_enqueue_script( 'codenitcaptcha-recaptcha-js', CODENITCAPTCHA_PLUGIN_DIR_URL . 'assets/js/scripts.js', array(), '1.0.9', true );
    179179            \wp_enqueue_script( 'google-recaptcha', $url, array( 'codenitcaptcha-recaptcha-js' ), CODENITCAPTCHA_VERSION, true );
    180180
     
    225225
    226226        // Verify nonce first
    227         if (!isset($_POST['codenitcaptcha_nonce']) ||
    228             !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {
    229             return array(
    230                 'status' => 'error',
    231                 'message' => 'nonce_invalid'
    232             );
     227        if(isset($_POST['wooregister']) && $_POST['wooregister'] == '_codenitcaptcha_nonce_wcc_register') {
     228            if (!isset($_POST['codenitcaptcha_nonce_woo_register']) ||
     229                !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce_woo_register'])), 'codenitcaptcha_action_woo_register')) {
     230                return array(
     231                    'status' => 'error',
     232                    'message' => 'nonce_invalid'
     233                );
     234            }
     235        } else {
     236            if (!isset($_POST['codenitcaptcha_nonce']) ||
     237                !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {
     238                return array(
     239                    'status' => 'error',
     240                    'message' => 'nonce_invalid'
     241                );
     242            }
    233243        }
    234244
  • codenitive-captcha/tags/1.0.4/includes/class-comments-captcha.php

    r3334736 r3334966  
    3636                $this->config->maybe_enqueue_script();
    3737                $site_key = $this->config->get_site_key_v2();
    38                 $captcha = '<div id="codenitcaptcha-comments-recaptcha" class="g-recaptcha" data-sitekey="' . \esc_attr($site_key) . '"></div>';
     38                $captcha = '<div class="g-recaptcha codenitcaptcha-recaptcha" data-sitekey="' . \esc_attr($site_key) . '"></div>';
    3939                $captcha .= \wp_nonce_field( 'codenitcaptcha_action', 'codenitcaptcha_nonce', true, false );
    4040           
  • codenitive-captcha/tags/1.0.4/includes/class-forms.php

    r3334736 r3334966  
    3434       
    3535            if ( $this->config->get_wcc_register() == 1 ) {
    36                 \add_action('woocommerce_register_form', array($this, 'display_captcha'), 20);
     36                \add_action('woocommerce_register_form', array($this, 'display_captcha_woo_register'), 20);
    3737                \add_filter('woocommerce_process_registration_errors', array($this, 'validate_registration_captcha'), 5, 4);
    3838            }
     
    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 id="codenitcaptcha-comments-recaptcha" class="g-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';
     113                $captcha = '<div class="g-recaptcha codenitcaptcha-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';
    114114            }
    115115
     
    118118
    119119        }
     120    }
     121
     122    public function display_captcha_woo_register(){
     123        $captcha = '<div id="codenitcaptcha-wooregister-recaptcha" class="g-recaptcha codenitcaptcha-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';
     124        echo '<input type="hidden" name="wooregister" value="_codenitcaptcha_nonce_wcc_register">';
     125        echo \wp_kses_post( \wp_nonce_field( 'codenitcaptcha_action_woo_register', 'codenitcaptcha_nonce_woo_register' ));
     126        echo \wp_kses_post( $captcha );
    120127    }
    121128
  • codenitive-captcha/trunk/assets/js/scripts.js

    r3334736 r3334966  
    4242            }
    4343        }
     44       
     45        const siteKey = CodenitCaptchaData?.siteKey;
    4446
    45         const siteKey = CodenitCaptchaData?.siteKey;
     47        if (siteKey) {
     48            const elements = document.querySelectorAll('.codenitcaptcha-recaptcha');
     49       
     50            elements.forEach((element) => {
     51                grecaptcha.render(element, {
     52                    sitekey: siteKey
     53                });
     54            });
     55        }
    4656
    47         if (siteKey && document.getElementById('codenitcaptcha-comments-recaptcha')) {
    48             grecaptcha.render('codenitcaptcha-comments-recaptcha', {
    49                 sitekey: siteKey
    50             });
    51         }
    5257
    5358    };
  • codenitive-captcha/trunk/includes/class-captcha-config.php

    r3334736 r3334966  
    176176            ), $url );
    177177
    178             \wp_enqueue_script( 'codenitcaptcha-recaptcha-js', CODENITCAPTCHA_PLUGIN_DIR_URL . 'assets/js/scripts.js', array(), '1.0.4', true );
     178            \wp_enqueue_script( 'codenitcaptcha-recaptcha-js', CODENITCAPTCHA_PLUGIN_DIR_URL . 'assets/js/scripts.js', array(), '1.0.9', true );
    179179            \wp_enqueue_script( 'google-recaptcha', $url, array( 'codenitcaptcha-recaptcha-js' ), CODENITCAPTCHA_VERSION, true );
    180180
     
    225225
    226226        // Verify nonce first
    227         if (!isset($_POST['codenitcaptcha_nonce']) ||
    228             !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {
    229             return array(
    230                 'status' => 'error',
    231                 'message' => 'nonce_invalid'
    232             );
     227        if(isset($_POST['wooregister']) && $_POST['wooregister'] == '_codenitcaptcha_nonce_wcc_register') {
     228            if (!isset($_POST['codenitcaptcha_nonce_woo_register']) ||
     229                !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce_woo_register'])), 'codenitcaptcha_action_woo_register')) {
     230                return array(
     231                    'status' => 'error',
     232                    'message' => 'nonce_invalid'
     233                );
     234            }
     235        } else {
     236            if (!isset($_POST['codenitcaptcha_nonce']) ||
     237                !\wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['codenitcaptcha_nonce'])), 'codenitcaptcha_action')) {
     238                return array(
     239                    'status' => 'error',
     240                    'message' => 'nonce_invalid'
     241                );
     242            }
    233243        }
    234244
  • codenitive-captcha/trunk/includes/class-comments-captcha.php

    r3334736 r3334966  
    3636                $this->config->maybe_enqueue_script();
    3737                $site_key = $this->config->get_site_key_v2();
    38                 $captcha = '<div id="codenitcaptcha-comments-recaptcha" class="g-recaptcha" data-sitekey="' . \esc_attr($site_key) . '"></div>';
     38                $captcha = '<div class="g-recaptcha codenitcaptcha-recaptcha" data-sitekey="' . \esc_attr($site_key) . '"></div>';
    3939                $captcha .= \wp_nonce_field( 'codenitcaptcha_action', 'codenitcaptcha_nonce', true, false );
    4040           
  • codenitive-captcha/trunk/includes/class-forms.php

    r3334736 r3334966  
    3434       
    3535            if ( $this->config->get_wcc_register() == 1 ) {
    36                 \add_action('woocommerce_register_form', array($this, 'display_captcha'), 20);
     36                \add_action('woocommerce_register_form', array($this, 'display_captcha_woo_register'), 20);
    3737                \add_filter('woocommerce_process_registration_errors', array($this, 'validate_registration_captcha'), 5, 4);
    3838            }
     
    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 id="codenitcaptcha-comments-recaptcha" class="g-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';
     113                $captcha = '<div class="g-recaptcha codenitcaptcha-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';
    114114            }
    115115
     
    118118
    119119        }
     120    }
     121
     122    public function display_captcha_woo_register(){
     123        $captcha = '<div id="codenitcaptcha-wooregister-recaptcha" class="g-recaptcha codenitcaptcha-recaptcha" data-sitekey="' . esc_attr($this->config->get_site_key_v2()) . '"></div>';
     124        echo '<input type="hidden" name="wooregister" value="_codenitcaptcha_nonce_wcc_register">';
     125        echo \wp_kses_post( \wp_nonce_field( 'codenitcaptcha_action_woo_register', 'codenitcaptcha_nonce_woo_register' ));
     126        echo \wp_kses_post( $captcha );
    120127    }
    121128
Note: See TracChangeset for help on using the changeset viewer.