Changeset 3077129
- Timestamp:
- 04/25/2024 03:45:03 PM (22 months ago)
- Location:
- adcaptcha
- Files:
-
- 12 edited
- 1 copied
-
tags/1.1.2 (copied) (copied from adcaptcha/trunk)
-
tags/1.1.2/adcaptcha.php (modified) (1 diff)
-
tags/1.1.2/readme.txt (modified) (2 diffs)
-
tags/1.1.2/src/Plugin/ContactForm7/Forms.php (modified) (3 diffs)
-
tags/1.1.2/src/Settings/Settings.php (modified) (1 diff)
-
tags/1.1.2/src/Widget/AdCaptcha.php (modified) (1 diff)
-
tags/1.1.2/src/Widget/Verify.php (modified) (3 diffs)
-
trunk/adcaptcha.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Plugin/ContactForm7/Forms.php (modified) (3 diffs)
-
trunk/src/Settings/Settings.php (modified) (1 diff)
-
trunk/src/Widget/AdCaptcha.php (modified) (1 diff)
-
trunk/src/Widget/Verify.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
adcaptcha/tags/1.1.2/adcaptcha.php
r3076499 r3077129 3 3 * Plugin Name: adCAPTCHA for WordPress 4 4 * Description: Secure your site. Elevate your brand. Boost Ad Revenue. 5 * Version: 1.1. 15 * Version: 1.1.2 6 6 * Requires at least: 6.4.2 7 7 * Requires PHP: 7.4 -
adcaptcha/tags/1.1.2/readme.txt
r3076499 r3077129 5 5 Requires at least: 6.0 6 6 Tested up to: 6.4 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 95 95 = 1.1.1 = 96 96 - 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 10 10 public function setup() { 11 11 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 ); 12 14 add_action( 'wp_enqueue_scripts', [ $this, 'reset_captcha_script' ], 9 ); 13 15 add_filter( 'wpcf7_form_elements', [ $this, 'captcha_trigger_filter' ], 20, 1 ); 16 add_filter('wpcf7_form_hidden_fields', [$this, 'add_adcaptcha_response_field']); 14 17 add_filter( 'wpcf7_spam', [ $this, 'verify' ], 9, 1 ); 15 18 } … … 17 20 public function verify( $spam ) { 18 21 if ( $spam ) { 19 return $spam;20 }22 return $spam; 23 } 21 24 25 $token = trim( $_POST['_wpcf7_adcaptcha_response']); 26 22 27 $verify = new Verify(); 23 $response = $verify->verify_token( );24 28 $response = $verify->verify_token($token); 29 25 30 if ( $response === false ) { 26 31 $spam = true; 32 27 33 add_filter('wpcf7_display_message', function($message, $status) { 28 34 if ($status == 'spam') { 29 $message = __( ' Incomplete captcha, Please try again.', 'adcaptcha' );35 $message = __( 'Please complete the I am human box', 'adcaptcha' ); 30 36 } 31 37 return $message; 32 38 }, 10, 2); 33 39 } 34 40 35 41 return $spam; 36 42 } … … 42 48 AdCaptcha::ob_captcha_trigger() . '$1', 43 49 $elements 44 ); 50 ); 51 } 52 53 public function add_adcaptcha_response_field($fields) { 54 return array_merge( $fields, array( 55 '_wpcf7_adcaptcha_response' => '', 56 ) ); 45 57 } 46 58 47 59 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 ); 49 99 } 50 100 } -
adcaptcha/tags/1.1.2/src/Settings/Settings.php
r3076499 r3077129 71 71 72 72 public function change_admin_footer_version() { 73 return 'Version 1.1. 1';73 return 'Version 1.1.2'; 74 74 } 75 75 } -
adcaptcha/tags/1.1.2/src/Widget/AdCaptcha.php
r3060548 r3077129 35 35 }); 36 36 ' . ($enableSubmitButton ? self::enable_submit_button() : '') . ' 37 const event = new CustomEvent("adcaptcha_onSuccess", { 38 detail: { successToken: window.adcap.successToken }, 39 }); 40 document.dispatchEvent(event); 37 41 } 38 42 });'; -
adcaptcha/tags/1.1.2/src/Widget/Verify.php
r3060548 r3077129 23 23 } 24 24 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 27 30 $apiKey = get_option('adcaptcha_api_key'); 28 31 $url = 'https://api.adcaptcha.com/v1/verify'; … … 41 44 42 45 if (is_wp_error($response)) { 46 update_option('adcaptcha_success_token', ''); 43 47 return false; 44 48 } … … 47 51 $message = json_decode($body); 48 52 if ($message && $message->message === 'Token verified') { 53 update_option('adcaptcha_success_token', ''); 49 54 return true; 50 55 } -
adcaptcha/trunk/adcaptcha.php
r3076499 r3077129 3 3 * Plugin Name: adCAPTCHA for WordPress 4 4 * Description: Secure your site. Elevate your brand. Boost Ad Revenue. 5 * Version: 1.1. 15 * Version: 1.1.2 6 6 * Requires at least: 6.4.2 7 7 * Requires PHP: 7.4 -
adcaptcha/trunk/readme.txt
r3076499 r3077129 5 5 Requires at least: 6.0 6 6 Tested up to: 6.4 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 95 95 = 1.1.1 = 96 96 - 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 10 10 public function setup() { 11 11 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 ); 12 14 add_action( 'wp_enqueue_scripts', [ $this, 'reset_captcha_script' ], 9 ); 13 15 add_filter( 'wpcf7_form_elements', [ $this, 'captcha_trigger_filter' ], 20, 1 ); 16 add_filter('wpcf7_form_hidden_fields', [$this, 'add_adcaptcha_response_field']); 14 17 add_filter( 'wpcf7_spam', [ $this, 'verify' ], 9, 1 ); 15 18 } … … 17 20 public function verify( $spam ) { 18 21 if ( $spam ) { 19 return $spam;20 }22 return $spam; 23 } 21 24 25 $token = trim( $_POST['_wpcf7_adcaptcha_response']); 26 22 27 $verify = new Verify(); 23 $response = $verify->verify_token( );24 28 $response = $verify->verify_token($token); 29 25 30 if ( $response === false ) { 26 31 $spam = true; 32 27 33 add_filter('wpcf7_display_message', function($message, $status) { 28 34 if ($status == 'spam') { 29 $message = __( ' Incomplete captcha, Please try again.', 'adcaptcha' );35 $message = __( 'Please complete the I am human box', 'adcaptcha' ); 30 36 } 31 37 return $message; 32 38 }, 10, 2); 33 39 } 34 40 35 41 return $spam; 36 42 } … … 42 48 AdCaptcha::ob_captcha_trigger() . '$1', 43 49 $elements 44 ); 50 ); 51 } 52 53 public function add_adcaptcha_response_field($fields) { 54 return array_merge( $fields, array( 55 '_wpcf7_adcaptcha_response' => '', 56 ) ); 45 57 } 46 58 47 59 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 ); 49 99 } 50 100 } -
adcaptcha/trunk/src/Settings/Settings.php
r3076499 r3077129 71 71 72 72 public function change_admin_footer_version() { 73 return 'Version 1.1. 1';73 return 'Version 1.1.2'; 74 74 } 75 75 } -
adcaptcha/trunk/src/Widget/AdCaptcha.php
r3060548 r3077129 35 35 }); 36 36 ' . ($enableSubmitButton ? self::enable_submit_button() : '') . ' 37 const event = new CustomEvent("adcaptcha_onSuccess", { 38 detail: { successToken: window.adcap.successToken }, 39 }); 40 document.dispatchEvent(event); 37 41 } 38 42 });'; -
adcaptcha/trunk/src/Widget/Verify.php
r3060548 r3077129 23 23 } 24 24 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 27 30 $apiKey = get_option('adcaptcha_api_key'); 28 31 $url = 'https://api.adcaptcha.com/v1/verify'; … … 41 44 42 45 if (is_wp_error($response)) { 46 update_option('adcaptcha_success_token', ''); 43 47 return false; 44 48 } … … 47 51 $message = json_decode($body); 48 52 if ($message && $message->message === 'Token verified') { 53 update_option('adcaptcha_success_token', ''); 49 54 return true; 50 55 }
Note: See TracChangeset
for help on using the changeset viewer.