Changeset 3080455
- Timestamp:
- 05/02/2024 02:18:50 PM (22 months ago)
- Location:
- adcaptcha
- Files:
-
- 24 added
- 32 edited
- 1 copied
-
tags/1.2.0 (copied) (copied from adcaptcha/trunk)
-
tags/1.2.0/adcaptcha.php (modified) (4 diffs)
-
tags/1.2.0/assets/ninjaForms_logo.png (added)
-
tags/1.2.0/assets/wpforms_logo.png (added)
-
tags/1.2.0/readme.txt (modified) (2 diffs)
-
tags/1.2.0/src/Instantiate.php (modified) (2 diffs)
-
tags/1.2.0/src/Plugin/AdCaptchaPlugin.php (added)
-
tags/1.2.0/src/Plugin/Comments.php (modified) (2 diffs)
-
tags/1.2.0/src/Plugin/ContactForm7/Forms.php (modified) (1 diff)
-
tags/1.2.0/src/Plugin/Login.php (modified) (3 diffs)
-
tags/1.2.0/src/Plugin/Mailchimp/Forms.php (modified) (4 diffs)
-
tags/1.2.0/src/Plugin/NinjaForms (added)
-
tags/1.2.0/src/Plugin/NinjaForms/AdCaptchaFieldController.js (added)
-
tags/1.2.0/src/Plugin/NinjaForms/AdcaptchaField.php (added)
-
tags/1.2.0/src/Plugin/NinjaForms/Forms.php (added)
-
tags/1.2.0/src/Plugin/NinjaForms/templates (added)
-
tags/1.2.0/src/Plugin/NinjaForms/templates/fields-adcaptcha.html (added)
-
tags/1.2.0/src/Plugin/PasswordReset.php (modified) (3 diffs)
-
tags/1.2.0/src/Plugin/Registration.php (modified) (3 diffs)
-
tags/1.2.0/src/Plugin/WPForms (added)
-
tags/1.2.0/src/Plugin/WPForms/AdCAPTCHA_WPForms_Field.php (added)
-
tags/1.2.0/src/Plugin/WPForms/Forms.php (added)
-
tags/1.2.0/src/Plugin/Woocommerce/Login.php (modified) (2 diffs)
-
tags/1.2.0/src/Plugin/Woocommerce/PasswordReset.php (modified) (2 diffs)
-
tags/1.2.0/src/Plugin/Woocommerce/Registration.php (modified) (2 diffs)
-
tags/1.2.0/src/Settings/Plugins.php (modified) (1 diff)
-
tags/1.2.0/src/Settings/Settings.php (modified) (2 diffs)
-
tags/1.2.0/src/Widget/AdCaptcha.php (modified) (3 diffs)
-
tags/1.2.0/src/Widget/Verify.php (modified) (4 diffs)
-
trunk/adcaptcha.php (modified) (4 diffs)
-
trunk/assets/ninjaForms_logo.png (added)
-
trunk/assets/wpforms_logo.png (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Instantiate.php (modified) (2 diffs)
-
trunk/src/Plugin/AdCaptchaPlugin.php (added)
-
trunk/src/Plugin/Comments.php (modified) (2 diffs)
-
trunk/src/Plugin/ContactForm7/Forms.php (modified) (1 diff)
-
trunk/src/Plugin/Login.php (modified) (3 diffs)
-
trunk/src/Plugin/Mailchimp/Forms.php (modified) (4 diffs)
-
trunk/src/Plugin/NinjaForms (added)
-
trunk/src/Plugin/NinjaForms/AdCaptchaFieldController.js (added)
-
trunk/src/Plugin/NinjaForms/AdcaptchaField.php (added)
-
trunk/src/Plugin/NinjaForms/Forms.php (added)
-
trunk/src/Plugin/NinjaForms/templates (added)
-
trunk/src/Plugin/NinjaForms/templates/fields-adcaptcha.html (added)
-
trunk/src/Plugin/PasswordReset.php (modified) (3 diffs)
-
trunk/src/Plugin/Registration.php (modified) (3 diffs)
-
trunk/src/Plugin/WPForms (added)
-
trunk/src/Plugin/WPForms/AdCAPTCHA_WPForms_Field.php (added)
-
trunk/src/Plugin/WPForms/Forms.php (added)
-
trunk/src/Plugin/Woocommerce/Login.php (modified) (2 diffs)
-
trunk/src/Plugin/Woocommerce/PasswordReset.php (modified) (2 diffs)
-
trunk/src/Plugin/Woocommerce/Registration.php (modified) (2 diffs)
-
trunk/src/Settings/Plugins.php (modified) (1 diff)
-
trunk/src/Settings/Settings.php (modified) (2 diffs)
-
trunk/src/Widget/AdCaptcha.php (modified) (3 diffs)
-
trunk/src/Widget/Verify.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
adcaptcha/tags/1.2.0/adcaptcha.php
r3077493 r3080455 3 3 * Plugin Name: adCAPTCHA for WordPress 4 4 * Description: Secure your site. Elevate your brand. Boost Ad Revenue. 5 * Version: 1. 1.35 * Version: 1.2.0 6 6 * Requires at least: 6.4.2 7 7 * Requires PHP: 7.4 … … 23 23 require_once plugin_dir_path(__FILE__) . 'src/Settings/General.php'; 24 24 require_once plugin_dir_path(__FILE__) . 'src/Settings/Plugins.php'; 25 require_once plugin_dir_path(__FILE__) . 'src/Plugin/AdCaptchaPlugin.php'; 25 26 require_once plugin_dir_path(__FILE__) . 'src/Plugin/Login.php'; 26 27 require_once plugin_dir_path(__FILE__) . 'src/Plugin/Registration.php'; … … 34 35 require_once plugin_dir_path(__FILE__) . 'src/Plugin/ContactForm7/Forms.php'; 35 36 require_once plugin_dir_path(__FILE__) . 'src/Plugin/Mailchimp/Forms.php'; 37 require_once plugin_dir_path(__FILE__) . 'src/Plugin/NinjaForms/Forms.php'; 38 require_once plugin_dir_path(__FILE__) . 'src/Plugin/WPForms/Forms.php'; 36 39 37 40 use AdCaptcha\Instantiate; 38 41 39 const PLUGIN_VERSION = '1.0.1'; 42 const PLUGIN_VERSION_ADCAPTCHA = '1.2.0'; 43 define('ADCAPTCHA_ERROR_MESSAGE', __( 'Please complete the I am human box.', 'adcaptcha' )); 40 44 41 45 // Deletes data saved in the wp db on plugin uninstall … … 45 49 delete_option( 'adcaptcha_api_key' ); 46 50 delete_option( 'adcaptcha_placement_id' ); 47 delete_option( 'adcaptcha_success_token' );48 51 delete_option( 'adcaptcha_render_captcha' ); 49 52 delete_option( 'adcaptcha_selected_plugins' ); -
adcaptcha/tags/1.2.0/readme.txt
r3077493 r3080455 4 4 Tags: spam, anti-spam, block bots, security, adCAPTCHA 5 5 Requires at least: 6.0 6 Tested up to: 6. 47 Stable tag: 1. 1.36 Tested up to: 6.5.2 7 Stable tag: 1.2.0 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 101 101 = 1.1.3 = 102 102 - Minor patch: Fix to cf7 error message 103 104 = 1.2.0 = 105 - Feature: Support for Ninja Forms 106 - Feature: Support for WPForms 107 - Test: WordPress v6.5.2 -
adcaptcha/tags/1.2.0/src/Instantiate.php
r3064464 r3080455 13 13 use AdCaptcha\Plugin\ContactFrom7\Froms\Forms as ContactForm7; 14 14 use AdCaptcha\Plugin\Mailchimp\Froms\Forms as MailchimpForms; 15 use AdCaptcha\Plugin\NinjaForms\Froms\Forms as NinjaForms; 16 use AdCaptcha\Plugin\WPForms\Froms\Forms as WPForms; 15 17 16 18 class Instantiate { 17 19 18 20 public function setup() { 19 $classes = array( 20 'Wordpress_Login' => new Login(), 21 'Wordpress_Register' => new Registration(), 22 'Wordpress_ForgotPassword' => new PasswordReset(), 23 'Wordpress_Comments' => new Comments(), 24 'Woocommerce_Login' => new WoocommerceLogin(), 25 'Woocommerce_ForgotPassword' => new WoocommercePasswordReset(), 26 'Woocommerce_Register' => new WoocommerceRegistration(), 27 'ContactForm7_Forms' => new ContactForm7(), 28 'Mailchimp_Forms' => new MailchimpForms(), 29 ); 21 22 if ( ! function_exists( 'is_plugin_active' ) ) { 23 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 24 } 25 26 $classes = [ 27 'Wordpress_Login' => [ 28 'instance' => Login::class, 29 'plugin' => [], 30 ], 31 'Wordpress_Register' => [ 32 'instance' => Registration::class, 33 'plugin' => [], 34 ], 35 'Wordpress_ForgotPassword' => [ 36 'instance' => PasswordReset::class, 37 'plugin' => [], 38 ], 39 'Wordpress_Comments' => [ 40 'instance' => Comments::class, 41 'plugin' => [], 42 ], 43 'Woocommerce_Login' => [ 44 'instance' => WoocommerceLogin::class, 45 'plugin' => [ 'woocommerce/woocommerce.php' ], 46 ], 47 'Woocommerce_ForgotPassword' => [ 48 'instance' => WoocommercePasswordReset::class, 49 'plugin' => [ 'woocommerce/woocommerce.php' ], 50 ], 51 'Woocommerce_Register' => [ 52 'instance' => WoocommerceRegistration::class, 53 'plugin' => [ 'woocommerce/woocommerce.php' ], 54 ], 55 'ContactForm7_Forms' => [ 56 'instance' => ContactForm7::class, 57 'plugin' => [ 'contact-form-7/wp-contact-form-7.php' ], 58 ], 59 'Mailchimp_Forms' => [ 60 'instance' => MailchimpForms::class, 61 'plugin' => [ 'mailchimp-for-wp/mailchimp-for-wp.php' ], 62 ], 63 'NinjaForms_Forms' => [ 64 'instance' => NinjaForms::class, 65 'plugin' => [ 'ninja-forms/ninja-forms.php' ], 66 ], 67 'WPForms_Forms' => [ 68 'instance' => WPForms::class, 69 'plugin' => [ 'wpforms-lite/wpforms.php', 'wpforms/wpforms.php' ], 70 ], 71 ]; 30 72 31 73 $selected_plugins = get_option('adcaptcha_selected_plugins') ? get_option('adcaptcha_selected_plugins') : array(); … … 37 79 foreach ($selected_plugins as $selected_plugin) { 38 80 if (isset($classes[$selected_plugin])) { 39 $classes[$selected_plugin]->setup(); 81 $className = $classes[$selected_plugin]['instance']; 82 if (empty($classes[$selected_plugin]['plugin'])) { 83 new $className(); 84 } else { 85 foreach ($classes[$selected_plugin]['plugin'] as $plugin) { 86 if (is_plugin_active($plugin)) { 87 $className = $classes[$selected_plugin]['instance']; 88 new $className(); 89 } 90 } 91 } 40 92 } 41 93 } -
adcaptcha/tags/1.2.0/src/Plugin/Comments.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Comments {10 class Comments extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'comment_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'comment_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_filter( 'comment_form_submit_field', [ $this, 'captcha_trigger_filter' ] ); 14 16 add_action( 'pre_comment_approved', [ $this, 'verify' ], 20, 2 ); … … 16 18 17 19 public function verify( $approved, array $commentdata ) { 20 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 18 21 $verify = new Verify(); 19 $response = $verify->verify_token( );22 $response = $verify->verify_token($successToken); 20 23 21 24 -
adcaptcha/tags/1.2.0/src/Plugin/ContactForm7/Forms.php
r3077493 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 8 class Forms {9 class Forms extends AdCaptchaPlugin { 9 10 10 11 public function setup() { -
adcaptcha/tags/1.2.0/src/Plugin/Login.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Login {10 class Login extends AdCaptchaPlugin { 10 11 11 12 public function setup() { … … 16 17 AdCaptcha::enqueue_scripts($enableSubmitButtonScript); 17 18 }); 19 add_action( 'login_enqueue_scripts', [ Verify::class, 'get_success_token' ] ); 18 20 add_action( 'login_enqueue_scripts', [ $this, 'disable_safari_auto_submit' ] ); 19 21 add_action( 'login_form', [ AdCaptcha::class, 'captcha_trigger' ] ); … … 22 24 23 25 public function verify( $errors ) { 26 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 24 27 $verify = new Verify(); 25 $response = $verify->verify_token( );28 $response = $verify->verify_token($successToken); 26 29 27 30 if ( $response === false ) { -
adcaptcha/tags/1.2.0/src/Plugin/Mailchimp/Forms.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 8 9 use MC4WP_Form; 10 use MC4WP_Form_Element; 9 11 10 class Forms {12 class Forms extends AdCaptchaPlugin { 11 13 12 14 public function setup() { 13 15 add_action( 'wp_enqueue_scripts', [ AdCaptcha::class, 'enqueue_scripts' ], 9 ); 16 add_action( 'wp_enqueue_scripts', [ Verify::class, 'get_success_token' ] ); 17 add_action( 'wp_enqueue_scripts', [ $this, 'block_submission' ], 9 ); 18 add_filter( 'mc4wp_form_content', [ $this, 'add_hidden_input' ], 20, 3 ); 14 19 add_action( 'admin_enqueue_scripts', [ $this, 'form_preview_setup_triggers' ], 9 ); 15 20 add_filter( 'mc4wp_form_errors', [ $this, 'verify' ], 10, 2 ); … … 18 23 $messages['invalid_captcha'] = [ 19 24 'type' => 'error', 20 'text' => __( 'Incomplete captcha, Please try again.', 'adCAPTCHA' ),25 'text' => ADCAPTCHA_ERROR_MESSAGE, 21 26 ]; 22 27 return $messages; … … 24 29 } 25 30 31 public function add_hidden_input( string $content, MC4WP_Form $form, MC4WP_Form_Element $element ): string { 32 return preg_replace( 33 '/(<(input|button).*?type=(["\']?)submit(["\']?))/', 34 '<input type="hidden" class="adcaptcha_successToken" name="adcaptcha_successToken">' . '$1', 35 $content 36 ); 37 } 38 26 39 public function verify( $errors, MC4WP_Form $form ) { 40 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 27 41 $verify = new Verify(); 28 $response = $verify->verify_token( );42 $response = $verify->verify_token($successToken); 29 43 30 44 if ( $response === false ) { … … 34 48 35 49 return $errors; 50 } 51 52 public function block_submission() { 53 $script = ' 54 document.addEventListener("DOMContentLoaded", function() { 55 var form = document.querySelector(".mc4wp-form"); 56 if (form) { 57 var submitButton =[... document.querySelectorAll("[type=\'submit\']")]; 58 if (submitButton) { 59 submitButton.forEach(function(submitButton) { 60 submitButton.addEventListener("click", function(event) { 61 if (!window.adcap || !window.adcap.successToken) { 62 event.preventDefault(); 63 var responseDiv = document.querySelector(".mc4wp-response"); 64 responseDiv.innerHTML = \'<div class="mc4wp-alert mc4wp-error" role="alert"><p>\' + adCaptchaErrorMessage + \'</p></div>\'; 65 return false; 66 } 67 }); 68 }); 69 } 70 } 71 });'; 72 73 wp_register_script('adcaptcha-script', '', [], false, true); 74 wp_localize_script('adcaptcha-script', 'adCaptchaErrorMessage', array(ADCAPTCHA_ERROR_MESSAGE)); 75 wp_add_inline_script('adcaptcha-script', $script); 36 76 } 37 77 -
adcaptcha/tags/1.2.0/src/Plugin/PasswordReset.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class PasswordReset {10 class PasswordReset extends AdCaptchaPlugin { 10 11 11 12 public function setup() { … … 13 14 $adCAPTCHAWordpressPasswordReset = $this; 14 15 add_action( 'lostpassword_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 16 add_action( 'lostpassword_form', [ Verify::class, 'get_success_token' ] ); 15 17 add_action( 'lostpassword_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 16 18 add_action( 'lostpassword_post', [ $adCAPTCHAWordpressPasswordReset, 'verify' ], 10, 1 ); … … 18 20 19 21 public function verify( $errors ) { 20 $response = Verify::verify_token(); 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 23 $verify = new Verify(); 24 $response = $verify->verify_token($successToken); 21 25 22 26 if ( !$response ) { -
adcaptcha/tags/1.2.0/src/Plugin/Registration.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Registration {10 class Registration extends AdCaptchaPlugin { 10 11 11 12 public function setup() { … … 13 14 $adCAPTCHAWordpressRegistration = $this; 14 15 add_action( 'register_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 16 add_action( 'register_form', [ Verify::class, 'get_success_token' ] ); 15 17 add_action( 'register_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 16 18 add_action( 'registration_errors', [ $adCAPTCHAWordpressRegistration, 'verify' ], 10, 1 ); … … 18 20 19 21 public function verify( $errors ) { 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 20 23 $verify = new Verify(); 21 $response = $verify->verify_token( );24 $response = $verify->verify_token($successToken); 22 25 23 26 -
adcaptcha/tags/1.2.0/src/Plugin/Woocommerce/Login.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Login {10 class Login extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'woocommerce_login_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'woocommerce_login_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_action( 'woocommerce_login_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 14 16 add_filter( 'woocommerce_process_login_errors', [ $this, 'verify' ], 10, 3 ); … … 18 20 global $adCAPTCHAWordpressLogin; 19 21 remove_action( 'wp_authenticate_user', [ $adCAPTCHAWordpressLogin, 'verify' ], 10 ); 20 $response = Verify::verify_token(); 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 23 $response = Verify::verify_token($successToken); 21 24 22 25 if ( $response === false ) { -
adcaptcha/tags/1.2.0/src/Plugin/Woocommerce/PasswordReset.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class PasswordReset {10 class PasswordReset extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'woocommerce_lostpassword_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'woocommerce_lostpassword_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_action( 'woocommerce_lostpassword_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 14 16 add_action( 'wp_loaded', [ $this, 'remove_wp_action' ], 10 ); … … 22 24 23 25 public function verify( $error ) { 24 $response = Verify::verify_token(); 26 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 27 $response = Verify::verify_token($successToken); 25 28 26 29 if ( !$response ) { -
adcaptcha/tags/1.2.0/src/Plugin/Woocommerce/Registration.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Registration {10 class Registration extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'woocommerce_register_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'woocommerce_register_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_action( 'woocommerce_register_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 14 16 add_filter( 'woocommerce_registration_errors', [ $this, 'verify' ], 10, 3 ); … … 18 20 global $adCAPTCHAWordpressRegistration; 19 21 remove_action( 'registration_errors', [ $adCAPTCHAWordpressRegistration, 'verify' ], 10 ); 20 $response = Verify::verify_token(); 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 23 $response = Verify::verify_token($successToken); 21 24 22 25 if ( !$response ) { -
adcaptcha/tags/1.2.0/src/Settings/Plugins.php
r3064464 r3080455 25 25 'label' => 'Mailchimp', 26 26 'logo' => 'mailchimp_logo.png', 27 'options' => array('Forms') 28 ), 29 array( 30 'label' => 'NinjaForms', 31 'logo' => 'ninjaForms_logo.png', 32 'options' => array('Forms') 33 ), 34 array( 35 'label' => 'WPForms', 36 'logo' => 'wpforms_logo.png', 27 37 'options' => array('Forms') 28 38 ), -
adcaptcha/tags/1.2.0/src/Settings/Settings.php
r3077493 r3080455 22 22 23 23 public function add_styles_to_settings() { 24 wp_enqueue_style('adcaptcha-admin-styles', plugins_url('../styles/settings.css', __FILE__), array(), PLUGIN_VERSION );24 wp_enqueue_style('adcaptcha-admin-styles', plugins_url('../styles/settings.css', __FILE__), array(), PLUGIN_VERSION_ADCAPTCHA); 25 25 } 26 26 … … 71 71 72 72 public function change_admin_footer_version() { 73 return 'Version 1. 1.3';73 return 'Version 1.2.0'; 74 74 } 75 75 } -
adcaptcha/tags/1.2.0/src/Widget/AdCaptcha.php
r3077129 r3080455 6 6 7 7 public static function enqueue_scripts($enableSubmitButton = false) { 8 wp_enqueue_script('adcaptcha-script', 'https://widget.adcaptcha.com/index.js', array('jquery'), PLUGIN_VERSION , true);8 wp_enqueue_script('adcaptcha-script', 'https://widget.adcaptcha.com/index.js', array('jquery'), PLUGIN_VERSION_ADCAPTCHA, true); 9 9 10 10 $ajax_nonce = wp_create_nonce("adcaptcha_nonce"); … … 20 20 }'); 21 21 } 22 22 23 23 public static function setupScript($enableSubmitButton = false) { 24 24 return 'window.adcap.init(); 25 25 window.adcap.setupTriggers({ 26 26 onComplete: () => { 27 jQuery.ajax({28 url: adcaptcha_vars.ajax_url,29 type: "POST",30 data: {31 action: "save_token",32 successToken: window.adcap.successToken,33 nonce: adcaptcha_vars.nonce,34 }35 });36 27 ' . ($enableSubmitButton ? self::enable_submit_button() : '') . ' 37 28 const event = new CustomEvent("adcaptcha_onSuccess", { … … 58 49 59 50 public static function captcha_trigger() { 60 printf('<div data-adcaptcha="' . esc_attr(get_option('adcaptcha_placement_id')) . '" style="margin-bottom: 20px; max-width: 400px; "></div>');51 printf('<div data-adcaptcha="' . esc_attr(get_option('adcaptcha_placement_id')) . '" style="margin-bottom: 20px; max-width: 400px; outline: none !important;"></div><input type="hidden" class="adcaptcha_successToken" name="adcaptcha_successToken">'); 61 52 } 62 53 } -
adcaptcha/tags/1.2.0/src/Widget/Verify.php
r3077129 r3080455 4 4 5 5 class Verify { 6 public static function verify_token($successToken) { 7 $apiKey = get_option('adcaptcha_api_key'); 6 8 7 // The actions are triggered after a post request is sent with action save_token 8 public static function init() { 9 add_action('wp_ajax_save_token', array(__CLASS__, 'save_token')); 10 add_action('wp_ajax_nopriv_save_token', array(__CLASS__, 'save_token')); 11 } 12 13 // Gets the successToken from the captcha trigger post request 14 public static function save_token() { 15 check_ajax_referer('adcaptcha_nonce', 'nonce'); 16 $successToken = sanitize_text_field(wp_unslash($_POST['successToken'])); 17 if (isset($successToken)) { 18 update_option('adcaptcha_success_token', $successToken); 19 wp_send_json_success('Success'); 20 } else { 21 wp_send_json_success('Failed'); 22 } 23 } 24 25 public static function verify_token($successToken = null) { 26 if (empty($successToken)) { 27 $successToken = get_option('adcaptcha_success_token'); 9 if (!$successToken || !$apiKey) { 10 return false; 28 11 } 29 12 30 $apiKey = get_option('adcaptcha_api_key');31 13 $url = 'https://api.adcaptcha.com/v1/verify'; 32 14 $body = wp_json_encode([ … … 44 26 45 27 if (is_wp_error($response)) { 46 update_option('adcaptcha_success_token', '');47 28 return false; 48 29 } … … 51 32 $message = json_decode($body); 52 33 if ($message && $message->message === 'Token verified') { 53 update_option('adcaptcha_success_token', '');54 34 return true; 55 35 } … … 57 37 return false; 58 38 } 39 40 public function get_success_token() { 41 $script = ' 42 document.addEventListener("DOMContentLoaded", function() { 43 document.addEventListener("adcaptcha_onSuccess", function(e) { 44 var elements = document.querySelectorAll(".adcaptcha_successToken"); 45 elements.forEach(function(element) { 46 element.value = e.detail.successToken; 47 }); 48 }); 49 });'; 50 51 wp_add_inline_script( 'adcaptcha-script', $script ); 52 } 59 53 } 60 61 Verify::init(); -
adcaptcha/trunk/adcaptcha.php
r3077493 r3080455 3 3 * Plugin Name: adCAPTCHA for WordPress 4 4 * Description: Secure your site. Elevate your brand. Boost Ad Revenue. 5 * Version: 1. 1.35 * Version: 1.2.0 6 6 * Requires at least: 6.4.2 7 7 * Requires PHP: 7.4 … … 23 23 require_once plugin_dir_path(__FILE__) . 'src/Settings/General.php'; 24 24 require_once plugin_dir_path(__FILE__) . 'src/Settings/Plugins.php'; 25 require_once plugin_dir_path(__FILE__) . 'src/Plugin/AdCaptchaPlugin.php'; 25 26 require_once plugin_dir_path(__FILE__) . 'src/Plugin/Login.php'; 26 27 require_once plugin_dir_path(__FILE__) . 'src/Plugin/Registration.php'; … … 34 35 require_once plugin_dir_path(__FILE__) . 'src/Plugin/ContactForm7/Forms.php'; 35 36 require_once plugin_dir_path(__FILE__) . 'src/Plugin/Mailchimp/Forms.php'; 37 require_once plugin_dir_path(__FILE__) . 'src/Plugin/NinjaForms/Forms.php'; 38 require_once plugin_dir_path(__FILE__) . 'src/Plugin/WPForms/Forms.php'; 36 39 37 40 use AdCaptcha\Instantiate; 38 41 39 const PLUGIN_VERSION = '1.0.1'; 42 const PLUGIN_VERSION_ADCAPTCHA = '1.2.0'; 43 define('ADCAPTCHA_ERROR_MESSAGE', __( 'Please complete the I am human box.', 'adcaptcha' )); 40 44 41 45 // Deletes data saved in the wp db on plugin uninstall … … 45 49 delete_option( 'adcaptcha_api_key' ); 46 50 delete_option( 'adcaptcha_placement_id' ); 47 delete_option( 'adcaptcha_success_token' );48 51 delete_option( 'adcaptcha_render_captcha' ); 49 52 delete_option( 'adcaptcha_selected_plugins' ); -
adcaptcha/trunk/readme.txt
r3077493 r3080455 4 4 Tags: spam, anti-spam, block bots, security, adCAPTCHA 5 5 Requires at least: 6.0 6 Tested up to: 6. 47 Stable tag: 1. 1.36 Tested up to: 6.5.2 7 Stable tag: 1.2.0 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 101 101 = 1.1.3 = 102 102 - Minor patch: Fix to cf7 error message 103 104 = 1.2.0 = 105 - Feature: Support for Ninja Forms 106 - Feature: Support for WPForms 107 - Test: WordPress v6.5.2 -
adcaptcha/trunk/src/Instantiate.php
r3064464 r3080455 13 13 use AdCaptcha\Plugin\ContactFrom7\Froms\Forms as ContactForm7; 14 14 use AdCaptcha\Plugin\Mailchimp\Froms\Forms as MailchimpForms; 15 use AdCaptcha\Plugin\NinjaForms\Froms\Forms as NinjaForms; 16 use AdCaptcha\Plugin\WPForms\Froms\Forms as WPForms; 15 17 16 18 class Instantiate { 17 19 18 20 public function setup() { 19 $classes = array( 20 'Wordpress_Login' => new Login(), 21 'Wordpress_Register' => new Registration(), 22 'Wordpress_ForgotPassword' => new PasswordReset(), 23 'Wordpress_Comments' => new Comments(), 24 'Woocommerce_Login' => new WoocommerceLogin(), 25 'Woocommerce_ForgotPassword' => new WoocommercePasswordReset(), 26 'Woocommerce_Register' => new WoocommerceRegistration(), 27 'ContactForm7_Forms' => new ContactForm7(), 28 'Mailchimp_Forms' => new MailchimpForms(), 29 ); 21 22 if ( ! function_exists( 'is_plugin_active' ) ) { 23 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 24 } 25 26 $classes = [ 27 'Wordpress_Login' => [ 28 'instance' => Login::class, 29 'plugin' => [], 30 ], 31 'Wordpress_Register' => [ 32 'instance' => Registration::class, 33 'plugin' => [], 34 ], 35 'Wordpress_ForgotPassword' => [ 36 'instance' => PasswordReset::class, 37 'plugin' => [], 38 ], 39 'Wordpress_Comments' => [ 40 'instance' => Comments::class, 41 'plugin' => [], 42 ], 43 'Woocommerce_Login' => [ 44 'instance' => WoocommerceLogin::class, 45 'plugin' => [ 'woocommerce/woocommerce.php' ], 46 ], 47 'Woocommerce_ForgotPassword' => [ 48 'instance' => WoocommercePasswordReset::class, 49 'plugin' => [ 'woocommerce/woocommerce.php' ], 50 ], 51 'Woocommerce_Register' => [ 52 'instance' => WoocommerceRegistration::class, 53 'plugin' => [ 'woocommerce/woocommerce.php' ], 54 ], 55 'ContactForm7_Forms' => [ 56 'instance' => ContactForm7::class, 57 'plugin' => [ 'contact-form-7/wp-contact-form-7.php' ], 58 ], 59 'Mailchimp_Forms' => [ 60 'instance' => MailchimpForms::class, 61 'plugin' => [ 'mailchimp-for-wp/mailchimp-for-wp.php' ], 62 ], 63 'NinjaForms_Forms' => [ 64 'instance' => NinjaForms::class, 65 'plugin' => [ 'ninja-forms/ninja-forms.php' ], 66 ], 67 'WPForms_Forms' => [ 68 'instance' => WPForms::class, 69 'plugin' => [ 'wpforms-lite/wpforms.php', 'wpforms/wpforms.php' ], 70 ], 71 ]; 30 72 31 73 $selected_plugins = get_option('adcaptcha_selected_plugins') ? get_option('adcaptcha_selected_plugins') : array(); … … 37 79 foreach ($selected_plugins as $selected_plugin) { 38 80 if (isset($classes[$selected_plugin])) { 39 $classes[$selected_plugin]->setup(); 81 $className = $classes[$selected_plugin]['instance']; 82 if (empty($classes[$selected_plugin]['plugin'])) { 83 new $className(); 84 } else { 85 foreach ($classes[$selected_plugin]['plugin'] as $plugin) { 86 if (is_plugin_active($plugin)) { 87 $className = $classes[$selected_plugin]['instance']; 88 new $className(); 89 } 90 } 91 } 40 92 } 41 93 } -
adcaptcha/trunk/src/Plugin/Comments.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Comments {10 class Comments extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'comment_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'comment_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_filter( 'comment_form_submit_field', [ $this, 'captcha_trigger_filter' ] ); 14 16 add_action( 'pre_comment_approved', [ $this, 'verify' ], 20, 2 ); … … 16 18 17 19 public function verify( $approved, array $commentdata ) { 20 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 18 21 $verify = new Verify(); 19 $response = $verify->verify_token( );22 $response = $verify->verify_token($successToken); 20 23 21 24 -
adcaptcha/trunk/src/Plugin/ContactForm7/Forms.php
r3077493 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 8 class Forms {9 class Forms extends AdCaptchaPlugin { 9 10 10 11 public function setup() { -
adcaptcha/trunk/src/Plugin/Login.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Login {10 class Login extends AdCaptchaPlugin { 10 11 11 12 public function setup() { … … 16 17 AdCaptcha::enqueue_scripts($enableSubmitButtonScript); 17 18 }); 19 add_action( 'login_enqueue_scripts', [ Verify::class, 'get_success_token' ] ); 18 20 add_action( 'login_enqueue_scripts', [ $this, 'disable_safari_auto_submit' ] ); 19 21 add_action( 'login_form', [ AdCaptcha::class, 'captcha_trigger' ] ); … … 22 24 23 25 public function verify( $errors ) { 26 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 24 27 $verify = new Verify(); 25 $response = $verify->verify_token( );28 $response = $verify->verify_token($successToken); 26 29 27 30 if ( $response === false ) { -
adcaptcha/trunk/src/Plugin/Mailchimp/Forms.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 8 9 use MC4WP_Form; 10 use MC4WP_Form_Element; 9 11 10 class Forms {12 class Forms extends AdCaptchaPlugin { 11 13 12 14 public function setup() { 13 15 add_action( 'wp_enqueue_scripts', [ AdCaptcha::class, 'enqueue_scripts' ], 9 ); 16 add_action( 'wp_enqueue_scripts', [ Verify::class, 'get_success_token' ] ); 17 add_action( 'wp_enqueue_scripts', [ $this, 'block_submission' ], 9 ); 18 add_filter( 'mc4wp_form_content', [ $this, 'add_hidden_input' ], 20, 3 ); 14 19 add_action( 'admin_enqueue_scripts', [ $this, 'form_preview_setup_triggers' ], 9 ); 15 20 add_filter( 'mc4wp_form_errors', [ $this, 'verify' ], 10, 2 ); … … 18 23 $messages['invalid_captcha'] = [ 19 24 'type' => 'error', 20 'text' => __( 'Incomplete captcha, Please try again.', 'adCAPTCHA' ),25 'text' => ADCAPTCHA_ERROR_MESSAGE, 21 26 ]; 22 27 return $messages; … … 24 29 } 25 30 31 public function add_hidden_input( string $content, MC4WP_Form $form, MC4WP_Form_Element $element ): string { 32 return preg_replace( 33 '/(<(input|button).*?type=(["\']?)submit(["\']?))/', 34 '<input type="hidden" class="adcaptcha_successToken" name="adcaptcha_successToken">' . '$1', 35 $content 36 ); 37 } 38 26 39 public function verify( $errors, MC4WP_Form $form ) { 40 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 27 41 $verify = new Verify(); 28 $response = $verify->verify_token( );42 $response = $verify->verify_token($successToken); 29 43 30 44 if ( $response === false ) { … … 34 48 35 49 return $errors; 50 } 51 52 public function block_submission() { 53 $script = ' 54 document.addEventListener("DOMContentLoaded", function() { 55 var form = document.querySelector(".mc4wp-form"); 56 if (form) { 57 var submitButton =[... document.querySelectorAll("[type=\'submit\']")]; 58 if (submitButton) { 59 submitButton.forEach(function(submitButton) { 60 submitButton.addEventListener("click", function(event) { 61 if (!window.adcap || !window.adcap.successToken) { 62 event.preventDefault(); 63 var responseDiv = document.querySelector(".mc4wp-response"); 64 responseDiv.innerHTML = \'<div class="mc4wp-alert mc4wp-error" role="alert"><p>\' + adCaptchaErrorMessage + \'</p></div>\'; 65 return false; 66 } 67 }); 68 }); 69 } 70 } 71 });'; 72 73 wp_register_script('adcaptcha-script', '', [], false, true); 74 wp_localize_script('adcaptcha-script', 'adCaptchaErrorMessage', array(ADCAPTCHA_ERROR_MESSAGE)); 75 wp_add_inline_script('adcaptcha-script', $script); 36 76 } 37 77 -
adcaptcha/trunk/src/Plugin/PasswordReset.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class PasswordReset {10 class PasswordReset extends AdCaptchaPlugin { 10 11 11 12 public function setup() { … … 13 14 $adCAPTCHAWordpressPasswordReset = $this; 14 15 add_action( 'lostpassword_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 16 add_action( 'lostpassword_form', [ Verify::class, 'get_success_token' ] ); 15 17 add_action( 'lostpassword_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 16 18 add_action( 'lostpassword_post', [ $adCAPTCHAWordpressPasswordReset, 'verify' ], 10, 1 ); … … 18 20 19 21 public function verify( $errors ) { 20 $response = Verify::verify_token(); 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 23 $verify = new Verify(); 24 $response = $verify->verify_token($successToken); 21 25 22 26 if ( !$response ) { -
adcaptcha/trunk/src/Plugin/Registration.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Registration {10 class Registration extends AdCaptchaPlugin { 10 11 11 12 public function setup() { … … 13 14 $adCAPTCHAWordpressRegistration = $this; 14 15 add_action( 'register_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 16 add_action( 'register_form', [ Verify::class, 'get_success_token' ] ); 15 17 add_action( 'register_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 16 18 add_action( 'registration_errors', [ $adCAPTCHAWordpressRegistration, 'verify' ], 10, 1 ); … … 18 20 19 21 public function verify( $errors ) { 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 20 23 $verify = new Verify(); 21 $response = $verify->verify_token( );24 $response = $verify->verify_token($successToken); 22 25 23 26 -
adcaptcha/trunk/src/Plugin/Woocommerce/Login.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Login {10 class Login extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'woocommerce_login_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'woocommerce_login_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_action( 'woocommerce_login_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 14 16 add_filter( 'woocommerce_process_login_errors', [ $this, 'verify' ], 10, 3 ); … … 18 20 global $adCAPTCHAWordpressLogin; 19 21 remove_action( 'wp_authenticate_user', [ $adCAPTCHAWordpressLogin, 'verify' ], 10 ); 20 $response = Verify::verify_token(); 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 23 $response = Verify::verify_token($successToken); 21 24 22 25 if ( $response === false ) { -
adcaptcha/trunk/src/Plugin/Woocommerce/PasswordReset.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class PasswordReset {10 class PasswordReset extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'woocommerce_lostpassword_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'woocommerce_lostpassword_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_action( 'woocommerce_lostpassword_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 14 16 add_action( 'wp_loaded', [ $this, 'remove_wp_action' ], 10 ); … … 22 24 23 25 public function verify( $error ) { 24 $response = Verify::verify_token(); 26 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 27 $response = Verify::verify_token($successToken); 25 28 26 29 if ( !$response ) { -
adcaptcha/trunk/src/Plugin/Woocommerce/Registration.php
r3060548 r3080455 5 5 use AdCaptcha\Widget\AdCaptcha\AdCaptcha; 6 6 use AdCaptcha\Widget\Verify\Verify; 7 use AdCaptcha\AdCaptchaPlugin\AdCaptchaPlugin; 7 8 use WP_Error; 8 9 9 class Registration {10 class Registration extends AdCaptchaPlugin { 10 11 11 12 public function setup() { 12 13 add_action( 'woocommerce_register_form', [ AdCaptcha::class, 'enqueue_scripts' ] ); 14 add_action( 'woocommerce_register_form', [ Verify::class, 'get_success_token' ] ); 13 15 add_action( 'woocommerce_register_form', [ AdCaptcha::class, 'captcha_trigger' ] ); 14 16 add_filter( 'woocommerce_registration_errors', [ $this, 'verify' ], 10, 3 ); … … 18 20 global $adCAPTCHAWordpressRegistration; 19 21 remove_action( 'registration_errors', [ $adCAPTCHAWordpressRegistration, 'verify' ], 10 ); 20 $response = Verify::verify_token(); 22 $successToken = sanitize_text_field(wp_unslash($_POST['adcaptcha_successToken'])); 23 $response = Verify::verify_token($successToken); 21 24 22 25 if ( !$response ) { -
adcaptcha/trunk/src/Settings/Plugins.php
r3064464 r3080455 25 25 'label' => 'Mailchimp', 26 26 'logo' => 'mailchimp_logo.png', 27 'options' => array('Forms') 28 ), 29 array( 30 'label' => 'NinjaForms', 31 'logo' => 'ninjaForms_logo.png', 32 'options' => array('Forms') 33 ), 34 array( 35 'label' => 'WPForms', 36 'logo' => 'wpforms_logo.png', 27 37 'options' => array('Forms') 28 38 ), -
adcaptcha/trunk/src/Settings/Settings.php
r3077493 r3080455 22 22 23 23 public function add_styles_to_settings() { 24 wp_enqueue_style('adcaptcha-admin-styles', plugins_url('../styles/settings.css', __FILE__), array(), PLUGIN_VERSION );24 wp_enqueue_style('adcaptcha-admin-styles', plugins_url('../styles/settings.css', __FILE__), array(), PLUGIN_VERSION_ADCAPTCHA); 25 25 } 26 26 … … 71 71 72 72 public function change_admin_footer_version() { 73 return 'Version 1. 1.3';73 return 'Version 1.2.0'; 74 74 } 75 75 } -
adcaptcha/trunk/src/Widget/AdCaptcha.php
r3077129 r3080455 6 6 7 7 public static function enqueue_scripts($enableSubmitButton = false) { 8 wp_enqueue_script('adcaptcha-script', 'https://widget.adcaptcha.com/index.js', array('jquery'), PLUGIN_VERSION , true);8 wp_enqueue_script('adcaptcha-script', 'https://widget.adcaptcha.com/index.js', array('jquery'), PLUGIN_VERSION_ADCAPTCHA, true); 9 9 10 10 $ajax_nonce = wp_create_nonce("adcaptcha_nonce"); … … 20 20 }'); 21 21 } 22 22 23 23 public static function setupScript($enableSubmitButton = false) { 24 24 return 'window.adcap.init(); 25 25 window.adcap.setupTriggers({ 26 26 onComplete: () => { 27 jQuery.ajax({28 url: adcaptcha_vars.ajax_url,29 type: "POST",30 data: {31 action: "save_token",32 successToken: window.adcap.successToken,33 nonce: adcaptcha_vars.nonce,34 }35 });36 27 ' . ($enableSubmitButton ? self::enable_submit_button() : '') . ' 37 28 const event = new CustomEvent("adcaptcha_onSuccess", { … … 58 49 59 50 public static function captcha_trigger() { 60 printf('<div data-adcaptcha="' . esc_attr(get_option('adcaptcha_placement_id')) . '" style="margin-bottom: 20px; max-width: 400px; "></div>');51 printf('<div data-adcaptcha="' . esc_attr(get_option('adcaptcha_placement_id')) . '" style="margin-bottom: 20px; max-width: 400px; outline: none !important;"></div><input type="hidden" class="adcaptcha_successToken" name="adcaptcha_successToken">'); 61 52 } 62 53 } -
adcaptcha/trunk/src/Widget/Verify.php
r3077129 r3080455 4 4 5 5 class Verify { 6 public static function verify_token($successToken) { 7 $apiKey = get_option('adcaptcha_api_key'); 6 8 7 // The actions are triggered after a post request is sent with action save_token 8 public static function init() { 9 add_action('wp_ajax_save_token', array(__CLASS__, 'save_token')); 10 add_action('wp_ajax_nopriv_save_token', array(__CLASS__, 'save_token')); 11 } 12 13 // Gets the successToken from the captcha trigger post request 14 public static function save_token() { 15 check_ajax_referer('adcaptcha_nonce', 'nonce'); 16 $successToken = sanitize_text_field(wp_unslash($_POST['successToken'])); 17 if (isset($successToken)) { 18 update_option('adcaptcha_success_token', $successToken); 19 wp_send_json_success('Success'); 20 } else { 21 wp_send_json_success('Failed'); 22 } 23 } 24 25 public static function verify_token($successToken = null) { 26 if (empty($successToken)) { 27 $successToken = get_option('adcaptcha_success_token'); 9 if (!$successToken || !$apiKey) { 10 return false; 28 11 } 29 12 30 $apiKey = get_option('adcaptcha_api_key');31 13 $url = 'https://api.adcaptcha.com/v1/verify'; 32 14 $body = wp_json_encode([ … … 44 26 45 27 if (is_wp_error($response)) { 46 update_option('adcaptcha_success_token', '');47 28 return false; 48 29 } … … 51 32 $message = json_decode($body); 52 33 if ($message && $message->message === 'Token verified') { 53 update_option('adcaptcha_success_token', '');54 34 return true; 55 35 } … … 57 37 return false; 58 38 } 39 40 public function get_success_token() { 41 $script = ' 42 document.addEventListener("DOMContentLoaded", function() { 43 document.addEventListener("adcaptcha_onSuccess", function(e) { 44 var elements = document.querySelectorAll(".adcaptcha_successToken"); 45 elements.forEach(function(element) { 46 element.value = e.detail.successToken; 47 }); 48 }); 49 });'; 50 51 wp_add_inline_script( 'adcaptcha-script', $script ); 52 } 59 53 } 60 61 Verify::init();
Note: See TracChangeset
for help on using the changeset viewer.