Plugin Directory

Changeset 3077129


Ignore:
Timestamp:
04/25/2024 03:45:03 PM (22 months ago)
Author:
adcaptcha
Message:

Update to version 1.1.2 from GitHub

Location:
adcaptcha
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • adcaptcha/tags/1.1.2/adcaptcha.php

    r3076499 r3077129  
    33 * Plugin Name: adCAPTCHA for WordPress
    44 * Description: Secure your site. Elevate your brand. Boost Ad Revenue.
    5  * Version: 1.1.1
     5 * Version: 1.1.2
    66 * Requires at least: 6.4.2
    77 * Requires PHP: 7.4
  • adcaptcha/tags/1.1.2/readme.txt

    r3076499 r3077129  
    55Requires at least: 6.0
    66Tested up to: 6.4
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    9595= 1.1.1 =
    9696- Minor patch: Fixed ContactForm7 not showing captcha on custom submit button
     97
     98= 1.1.2 =
     99- Minor patch: Fix to cf7 and hubspot with adCAPTCHA compatibility
  • adcaptcha/tags/1.1.2/src/Plugin/ContactForm7/Forms.php

    r3076499 r3077129  
    1010    public function setup() {
    1111        add_action( 'wp_enqueue_scripts', [ AdCaptcha::class, 'enqueue_scripts' ], 9 );
     12        add_action( 'wp_enqueue_scripts', [ $this, 'block_submission' ], 9 );
     13        add_action( 'wp_enqueue_scripts', [ $this, 'get_success_token' ], 9 );
    1214        add_action( 'wp_enqueue_scripts', [ $this, 'reset_captcha_script' ], 9 );
    1315        add_filter( 'wpcf7_form_elements', [ $this, 'captcha_trigger_filter' ], 20, 1 );
     16        add_filter('wpcf7_form_hidden_fields', [$this, 'add_adcaptcha_response_field']);
    1417        add_filter( 'wpcf7_spam', [ $this, 'verify' ], 9, 1 );
    1518    }
     
    1720    public function verify( $spam ) {
    1821        if ( $spam ) {
    19             return $spam;
    20         }
     22            return $spam;
     23        }
    2124
     25        $token = trim( $_POST['_wpcf7_adcaptcha_response']);
     26   
    2227        $verify = new Verify();
    23         $response = $verify->verify_token();
    24 
     28        $response = $verify->verify_token($token);
     29   
    2530        if ( $response === false ) {
    2631            $spam = true;
     32   
    2733            add_filter('wpcf7_display_message', function($message, $status) {
    2834                if ($status == 'spam') {
    29                     $message = __( 'Incomplete captcha, Please try again.', 'adcaptcha' );
     35                    $message = __( 'Please complete the I am human box', 'adcaptcha' );
    3036                }
    3137                return $message;
    3238            }, 10, 2);
    3339        }
    34 
     40   
    3541        return $spam;
    3642    }
     
    4248            AdCaptcha::ob_captcha_trigger() . '$1',
    4349            $elements
    44             );
     50        );
     51    }
     52
     53    public function add_adcaptcha_response_field($fields) {
     54        return array_merge( $fields, array(
     55            '_wpcf7_adcaptcha_response' => '',
     56        ) );
    4557    }
    4658
    4759    public function reset_captcha_script() {
    48         wp_add_inline_script( 'adcaptcha-script', 'document.addEventListener("wpcf7mailsent", function(event) { ' . AdCaptcha::setupScript() . ' }, false);' );
     60        wp_add_inline_script( 'adcaptcha-script', 'document.addEventListener("wpcf7mailsent", function(event) { ' . AdCaptcha::setupScript() . ' window.adcap.successToken = ""; }, false);' );
     61    }
     62
     63    public function block_submission() {
     64        $script = '
     65            document.addEventListener("DOMContentLoaded", function() {
     66                var form = document.querySelector(".wpcf7-form");
     67                if (form) {
     68                var submitButton =[... document.querySelectorAll(".wpcf7 [type=\'submit\']")];
     69                    if (submitButton) {
     70                        submitButton.forEach(function(submitButton) {
     71                            submitButton.addEventListener("click", function(event) {
     72                                if (!window.adcap || !window.adcap.successToken) {
     73                                    console.log(window.adcap.successToken);
     74                                    event.preventDefault();
     75                                    return false;
     76                                }
     77                            });
     78                        });
     79                    }
     80                }
     81            });';
     82   
     83        wp_add_inline_script( 'adcaptcha-script', $script );
     84    }
     85
     86    public function get_success_token() {
     87        $script = '
     88        document.addEventListener("DOMContentLoaded", function() {
     89            document.addEventListener("adcaptcha_onSuccess", (e) => {
     90                const t = document.querySelectorAll(
     91                "form.wpcf7-form input[name=\'_wpcf7_adcaptcha_response\']"
     92                );
     93                for (let c = 0; c < t.length; c++)
     94                t[c].setAttribute("value", e.detail.successToken);
     95            });
     96        });';
     97   
     98        wp_add_inline_script( 'adcaptcha-script', $script );
    4999    }
    50100}
  • adcaptcha/tags/1.1.2/src/Settings/Settings.php

    r3076499 r3077129  
    7171
    7272    public function change_admin_footer_version() {
    73         return 'Version 1.1.1';
     73        return 'Version 1.1.2';
    7474    }
    7575}
  • adcaptcha/tags/1.1.2/src/Widget/AdCaptcha.php

    r3060548 r3077129  
    3535                });
    3636                ' . ($enableSubmitButton ? self::enable_submit_button() : '') . '
     37                const event = new CustomEvent("adcaptcha_onSuccess", {
     38                    detail: { successToken: window.adcap.successToken },
     39                });
     40                document.dispatchEvent(event);
    3741            }
    3842        });';
  • adcaptcha/tags/1.1.2/src/Widget/Verify.php

    r3060548 r3077129  
    2323    }
    2424
    25     public static function verify_token() {
    26         $successToken = get_option('adcaptcha_success_token');
     25    public static function verify_token($successToken = null) {
     26        if (empty($successToken)) {
     27            $successToken = get_option('adcaptcha_success_token');
     28        }
     29
    2730        $apiKey = get_option('adcaptcha_api_key');
    2831        $url = 'https://api.adcaptcha.com/v1/verify';
     
    4144
    4245        if (is_wp_error($response)) {
     46            update_option('adcaptcha_success_token', '');
    4347            return false;
    4448        }
     
    4751        $message = json_decode($body);
    4852        if ($message && $message->message === 'Token verified') {
     53            update_option('adcaptcha_success_token', '');
    4954            return true;
    5055        }
  • adcaptcha/trunk/adcaptcha.php

    r3076499 r3077129  
    33 * Plugin Name: adCAPTCHA for WordPress
    44 * Description: Secure your site. Elevate your brand. Boost Ad Revenue.
    5  * Version: 1.1.1
     5 * Version: 1.1.2
    66 * Requires at least: 6.4.2
    77 * Requires PHP: 7.4
  • adcaptcha/trunk/readme.txt

    r3076499 r3077129  
    55Requires at least: 6.0
    66Tested up to: 6.4
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    9595= 1.1.1 =
    9696- Minor patch: Fixed ContactForm7 not showing captcha on custom submit button
     97
     98= 1.1.2 =
     99- Minor patch: Fix to cf7 and hubspot with adCAPTCHA compatibility
  • adcaptcha/trunk/src/Plugin/ContactForm7/Forms.php

    r3076499 r3077129  
    1010    public function setup() {
    1111        add_action( 'wp_enqueue_scripts', [ AdCaptcha::class, 'enqueue_scripts' ], 9 );
     12        add_action( 'wp_enqueue_scripts', [ $this, 'block_submission' ], 9 );
     13        add_action( 'wp_enqueue_scripts', [ $this, 'get_success_token' ], 9 );
    1214        add_action( 'wp_enqueue_scripts', [ $this, 'reset_captcha_script' ], 9 );
    1315        add_filter( 'wpcf7_form_elements', [ $this, 'captcha_trigger_filter' ], 20, 1 );
     16        add_filter('wpcf7_form_hidden_fields', [$this, 'add_adcaptcha_response_field']);
    1417        add_filter( 'wpcf7_spam', [ $this, 'verify' ], 9, 1 );
    1518    }
     
    1720    public function verify( $spam ) {
    1821        if ( $spam ) {
    19             return $spam;
    20         }
     22            return $spam;
     23        }
    2124
     25        $token = trim( $_POST['_wpcf7_adcaptcha_response']);
     26   
    2227        $verify = new Verify();
    23         $response = $verify->verify_token();
    24 
     28        $response = $verify->verify_token($token);
     29   
    2530        if ( $response === false ) {
    2631            $spam = true;
     32   
    2733            add_filter('wpcf7_display_message', function($message, $status) {
    2834                if ($status == 'spam') {
    29                     $message = __( 'Incomplete captcha, Please try again.', 'adcaptcha' );
     35                    $message = __( 'Please complete the I am human box', 'adcaptcha' );
    3036                }
    3137                return $message;
    3238            }, 10, 2);
    3339        }
    34 
     40   
    3541        return $spam;
    3642    }
     
    4248            AdCaptcha::ob_captcha_trigger() . '$1',
    4349            $elements
    44             );
     50        );
     51    }
     52
     53    public function add_adcaptcha_response_field($fields) {
     54        return array_merge( $fields, array(
     55            '_wpcf7_adcaptcha_response' => '',
     56        ) );
    4557    }
    4658
    4759    public function reset_captcha_script() {
    48         wp_add_inline_script( 'adcaptcha-script', 'document.addEventListener("wpcf7mailsent", function(event) { ' . AdCaptcha::setupScript() . ' }, false);' );
     60        wp_add_inline_script( 'adcaptcha-script', 'document.addEventListener("wpcf7mailsent", function(event) { ' . AdCaptcha::setupScript() . ' window.adcap.successToken = ""; }, false);' );
     61    }
     62
     63    public function block_submission() {
     64        $script = '
     65            document.addEventListener("DOMContentLoaded", function() {
     66                var form = document.querySelector(".wpcf7-form");
     67                if (form) {
     68                var submitButton =[... document.querySelectorAll(".wpcf7 [type=\'submit\']")];
     69                    if (submitButton) {
     70                        submitButton.forEach(function(submitButton) {
     71                            submitButton.addEventListener("click", function(event) {
     72                                if (!window.adcap || !window.adcap.successToken) {
     73                                    console.log(window.adcap.successToken);
     74                                    event.preventDefault();
     75                                    return false;
     76                                }
     77                            });
     78                        });
     79                    }
     80                }
     81            });';
     82   
     83        wp_add_inline_script( 'adcaptcha-script', $script );
     84    }
     85
     86    public function get_success_token() {
     87        $script = '
     88        document.addEventListener("DOMContentLoaded", function() {
     89            document.addEventListener("adcaptcha_onSuccess", (e) => {
     90                const t = document.querySelectorAll(
     91                "form.wpcf7-form input[name=\'_wpcf7_adcaptcha_response\']"
     92                );
     93                for (let c = 0; c < t.length; c++)
     94                t[c].setAttribute("value", e.detail.successToken);
     95            });
     96        });';
     97   
     98        wp_add_inline_script( 'adcaptcha-script', $script );
    4999    }
    50100}
  • adcaptcha/trunk/src/Settings/Settings.php

    r3076499 r3077129  
    7171
    7272    public function change_admin_footer_version() {
    73         return 'Version 1.1.1';
     73        return 'Version 1.1.2';
    7474    }
    7575}
  • adcaptcha/trunk/src/Widget/AdCaptcha.php

    r3060548 r3077129  
    3535                });
    3636                ' . ($enableSubmitButton ? self::enable_submit_button() : '') . '
     37                const event = new CustomEvent("adcaptcha_onSuccess", {
     38                    detail: { successToken: window.adcap.successToken },
     39                });
     40                document.dispatchEvent(event);
    3741            }
    3842        });';
  • adcaptcha/trunk/src/Widget/Verify.php

    r3060548 r3077129  
    2323    }
    2424
    25     public static function verify_token() {
    26         $successToken = get_option('adcaptcha_success_token');
     25    public static function verify_token($successToken = null) {
     26        if (empty($successToken)) {
     27            $successToken = get_option('adcaptcha_success_token');
     28        }
     29
    2730        $apiKey = get_option('adcaptcha_api_key');
    2831        $url = 'https://api.adcaptcha.com/v1/verify';
     
    4144
    4245        if (is_wp_error($response)) {
     46            update_option('adcaptcha_success_token', '');
    4347            return false;
    4448        }
     
    4751        $message = json_decode($body);
    4852        if ($message && $message->message === 'Token verified') {
     53            update_option('adcaptcha_success_token', '');
    4954            return true;
    5055        }
Note: See TracChangeset for help on using the changeset viewer.