From 5b1633cc18f31a88af917dd0bc7319ce34fee4f4 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Mon, 21 Apr 2025 21:11:41 +0300 Subject: [PATCH 1/2] New. Integration. Newsletter plugin integration implemented. --- inc/cleantalk-integrations-by-hook.php | 5 ++ inc/cleantalk-pluggable.php | 8 ++++ .../Antispam/Integrations/Newsletter.php | 48 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/Cleantalk/Antispam/Integrations/Newsletter.php diff --git a/inc/cleantalk-integrations-by-hook.php b/inc/cleantalk-integrations-by-hook.php index 4402f0850..407fa7037 100755 --- a/inc/cleantalk-integrations-by-hook.php +++ b/inc/cleantalk-integrations-by-hook.php @@ -398,6 +398,11 @@ 'setting' => 'forms__contact_forms_test', 'ajax' => true ), + 'Newsletter' => array( + 'hook' => 'newsletter_action', + 'setting' => 'forms__contact_forms_test', + 'ajax' => false + ), ); add_action('plugins_loaded', function () use ($apbct_active_integrations) { diff --git a/inc/cleantalk-pluggable.php b/inc/cleantalk-pluggable.php index 08f7cc53c..23f7dc0d8 100644 --- a/inc/cleantalk-pluggable.php +++ b/inc/cleantalk-pluggable.php @@ -1515,6 +1515,14 @@ class_exists('Cleantalk\Antispam\Integrations\CleantalkInternalForms') ) { return 'fusion_form/avada_theme skip'; } + + // skip Newsletter - have direct integration + if ( + apbct_is_plugin_active('newsletter/plugin.php') && + Request::getString('action') === 'tnp' + ) { + return 'Newsletter'; + } } else { /*****************************************/ /* Here is non-ajax requests skipping */ diff --git a/lib/Cleantalk/Antispam/Integrations/Newsletter.php b/lib/Cleantalk/Antispam/Integrations/Newsletter.php new file mode 100644 index 000000000..4272bdb80 --- /dev/null +++ b/lib/Cleantalk/Antispam/Integrations/Newsletter.php @@ -0,0 +1,48 @@ +getArray(); + if ( Post::getString('ct_bot_detector_event_token') ) { + $data['event_token'] = Post::get('ct_bot_detector_event_token'); + } + return $data; + } + } + + /** + * @inheritDoc + */ + public function doBlock($message) + { + global $ct_comment; + $ct_comment = $message; + ct_die($message, 403); + } +} From 8a9fb70f0656e9dd5794feccab871ad43c9662c4 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Tue, 22 Apr 2025 13:13:41 +0300 Subject: [PATCH 2/2] Fix. Integration. Newsletter integration fixed - prevent double requests. --- lib/Cleantalk/Antispam/Integrations/Newsletter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Cleantalk/Antispam/Integrations/Newsletter.php b/lib/Cleantalk/Antispam/Integrations/Newsletter.php index 4272bdb80..afe960ec7 100644 --- a/lib/Cleantalk/Antispam/Integrations/Newsletter.php +++ b/lib/Cleantalk/Antispam/Integrations/Newsletter.php @@ -3,6 +3,7 @@ namespace Cleantalk\Antispam\Integrations; use Cleantalk\ApbctWP\Variables\Post; +use Cleantalk\ApbctWP\Variables\Request; class Newsletter extends IntegrationBase { @@ -11,6 +12,11 @@ class Newsletter extends IntegrationBase */ public function getDataForChecking($argument) { + if ( Request::getString('nhr') ) { + // Prevent double redundant requests - this is the `success redirect` request + return null; + } + if ( $argument === 's' || $argument === 'subscribe' || @@ -34,6 +40,7 @@ public function getDataForChecking($argument) } return $data; } + return null; } /**