PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.0
5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 All 35 releases
double-opt-in / core / SpamMechanics.class.php

SpamMechanics.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 5.5.0, at core/SpamMechanics.class.php

144 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Forge12\ContactForm7\CF7DoubleOptIn;
4
5 use Forge12\Shared\LoggerInterface;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 }
10
11 class SpamMechanics
12 {
13 /** @var LoggerInterface */
14 private $logger;
15
16 /**
17 * Konstruktor
18 *
19 * @param LoggerInterface $logger
20 */
21 public function __construct(LoggerInterface $logger)
22 {
23 $this->logger = $logger;
24 $this->initialize();
25 }
26
27 /**
28 * Initialisiert die Spam-Mechanik-Deaktivierung,
29 * falls ein gültiger Opt-in-Link aufgerufen wurde.
30 *
31 * @return void
32 */
33 private function initialize()
34 {
35 $this->logDebug('disableSpamMechanics called');
36
37 $hash = isset($_GET['optin']) ? sanitize_text_field($_GET['optin']) : '';
38 if (empty($hash)) {
39 $this->logDebug('No opt-in hash found, skipping disableSpamMechanics');
40 return;
41 }
42
43 $optIn = OptIn::get_by_hash($hash);
44 if (!$optIn) {
45 $this->logDebug('Invalid opt-in hash, skipping disableSpamMechanics');
46 return;
47 }
48
49 if ($optIn->is_confirmed()) {
50 $this->logDebug('Opt-in already confirmed, skipping disableSpamMechanics');
51 return;
52 }
53
54 $this->disableForge12Captcha();
55 $this->disableGoogleRecaptcha();
56 $this->disableHCaptcha();
57
58 $this->logDebug('All spam protection filters removed');
59 }
60
61 /**
62 * Deaktiviert Forge12 Captcha-Integrationen für CF7, Avada und Elementor.
63 *
64 * @return void
65 */
66 private function disableForge12Captcha()
67 {
68 $filters = array(
69 'f12_cf7_captcha_is_installed_cf7',
70 'f12_cf7_captcha_is_installed_avada',
71 'f12_cf7_captcha_is_installed_elementor', // Tippfehler korrigiert
72 );
73
74 foreach ($filters as $filter) {
75 add_filter($filter, function ($is_active) {
76 return false;
77 }, 999, 1);
78 }
79
80 $this->logDebug('Forge12 Captcha filters removed');
81 }
82
83 /**
84 * Entfernt Google reCAPTCHA Filter für CF7.
85 *
86 * @return void
87 */
88 private function disableGoogleRecaptcha()
89 {
90 remove_filter('wpcf7_spam', 'wpcf7_recaptcha_verify_response', 9);
91 $this->logDebug('Google reCAPTCHA filter removed');
92 }
93
94 /**
95 * Deaktiviert hCaptcha-Validierung für CF7.
96 *
97 * @return void
98 */
99 private function disableHCaptcha()
100 {
101 if (class_exists('\HCaptcha\CF7\CF7')) {
102 global $wp_filter;
103
104 if (isset($wp_filter['wpcf7_validate'])) {
105 foreach ($wp_filter['wpcf7_validate']->callbacks as $priority => $hooks) {
106 foreach ($hooks as $key => $hook) {
107 if (is_array($hook['function']) && $hook['function'][0] instanceof \HCaptcha\CF7\CF7) {
108 remove_filter('wpcf7_validate', $hook['function'], $priority);
109 $this->logDebug('hCaptcha CF7 validation filter removed');
110 return;
111 }
112 }
113 }
114 }
115 }
116 }
117
118 /**
119 * Vereinheitlichter Logger für Debug-Nachrichten.
120 *
121 * @param string $message
122 * @param array $context
123 * @return void
124 */
125 private function logDebug($message, $context = array())
126 {
127 $defaultContext = array(
128 'plugin' => 'double-opt-in',
129 'class' => __CLASS__,
130 );
131
132 $context = array_merge($defaultContext, $context);
133
134 $this->logger->debug($message, $context);
135 }
136
137 /**
138 * @return LoggerInterface
139 */
140 public function get_logger()
141 {
142 return $this->logger;
143 }
144 }