PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 3.1.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v3.1.0
5.12.0 5.13.0 5.13.1 5.11.0 5.10.0 5.9.0 5.8.0 5.8.1 5.7.0 5.6.2 5.6.3 5.6.1 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 All 47 releases
double-opt-in / CF7DoubleOptIn.class.php

CF7DoubleOptIn.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 3.1.0, at CF7DoubleOptIn.class.php

375 lines 11.2 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\Logger;
6 use Forge12\Shared\LoggerInterface;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Plugin Name: Double Opt-In (Contact Form 7, Avada) - GDPR Ready
14 * Plugin URI: https://www.forge12.com/blog/so-verwendest-du-das-double-opt-in-fuer-contact-form-7/
15 * Description: This plugin allows you to add a double OptIn System to your Contact Form 7 & Avada Forms.
16 * Text Domain: double-opt-in
17 * Domain Path: /languages
18 * Version: 3.1.0
19 * Author: Forge12 Interactive GmbH
20 * Author URI: https://www.forge12.com
21 */
22 define( 'FORGE12_OPTIN_VERSION', '3.1.0' );
23 define( 'FORGE12_OPTIN_SLUG', 'f12-cf7-doubleoptin' );
24 define( 'FORGE12_OPTIN_BASENAME', plugin_basename( __FILE__ ) );
25
26
27 /**
28 * Dependencies
29 */
30 require_once( 'logger/logger.php' );
31 require_once('core/helpers/uuid.php');
32 require_once( 'core/telemetry.php' );
33 require_once( 'core/review.php' );
34 require_once( 'core/cron.php' );
35 require_once( 'core/BaseController.class.php' );
36
37 require_once( 'OnActivation.php' );
38 require_once( 'OnDeactivation.php' );
39 require_once( 'OnUpdate.php' );
40 require_once( 'compatibility/OptInFrontend.class.php' );
41
42 require_once( 'core/Messages.class.php' );
43 require_once( 'core/TemplateHandler.class.php' );
44 require_once( 'core/IPHelper.class.php' );
45 require_once( 'core/SanitizeHelper.class.php' );
46 require_once( 'core/Ajax.class.php' );
47 require_once( 'core/Compatibility.class.php' );
48 require_once( 'core/CleanUp.class.php' );
49 require_once( 'core/HTMLSelect.class.php' );
50 require_once( 'core/UI.class.php' );
51 require_once( 'core/UIPage.class.php' );
52 require_once( 'core/UIPageForm.class.php' );
53 require_once( 'core/OptIn.class.php' );
54 require_once( 'core/OptInLimitFilter.class.php' );
55 require_once( 'core/OptInSearchFilter.class.php' );
56 require_once( 'core/Category.class.php' );
57 require_once( 'core/CategoryOptions.class.php' );
58 require_once( 'core/Pagination.class.php' );
59
60 /**
61 * Class CF7DoubleOptIn
62 * Controller for the Custom Links.
63 *
64 * @package forge12\contactform7
65 */
66 class CF7DoubleOptIn {
67 private LoggerInterface $logger;
68 /**
69 * @var CF7DoubleOptIn|Null
70 */
71 private static $_instance = null;
72
73 /**
74 * @var TemplateHandler|null
75 */
76 private $TemplateHandler = null;
77
78 /**
79 * Get the singleton instance of CF7DoubleOptIn.
80 *
81 * @return CF7DoubleOptIn The singleton instance.
82 */
83 public static function getInstance() {
84 if ( self::$_instance == null ) {
85 self::$_instance = new self();
86 }
87
88 return self::$_instance;
89 }
90
91 /**
92 * Return a list containing the array with all data stored within the form
93 *
94 * @param int $postID
95 *
96 * @formatter:off
97 *
98 * @return {
99 * @type int $enable The Status of the OptIn, either 1 for enabled or 0 for disabled. Default: 0
100 * @type string $sender The E-Mail of the sender of the optIn mail
101 * @type string $subject The Subject of the OptIn Mail
102 * @type string $body The Content of the OptIn Mail
103 * @type string $recipient The Field that contains the E-Mail of the Recipient.
104 * @type int $page The Post ID of the confirmation page. Default: -1
105 * @type string $conditions Additional condition to dynamically enable / disable the optin.
106 * Default: disabled
107 * @type string $template The Template used for the OptIn Mail
108 * @type int $category The Category the OptIns will be assigned to.
109 * }
110 * @formatter:on
111 */
112 public function getParameter( $postID ) {
113 $this->get_logger()->debug( 'Fetching parameters', [
114 'plugin' => 'double-opt-in',
115 'class' => __CLASS__,
116 'method' => __METHOD__,
117 'post_id' => $postID,
118 ] );
119
120 $data = [
121 'enable' => 0,
122 'sender' => get_bloginfo( 'admin_email' ),
123 'sender_name' => '',
124 'subject' => '',
125 'body' => '',
126 'recipient' => '',
127 'page' => - 1,
128 'conditions' => 'disabled',
129 'template' => '',
130 'category' => 0,
131 ];
132
133 $data = apply_filters( 'f12_cf7_doubleoptin_get_parameter', $data );
134
135 if ( ! $postID ) {
136 $this->get_logger()->debug( 'No postID provided, returning defaults', [
137 'plugin' => 'double-opt-in',
138 ] );
139
140 return $data;
141 }
142
143 $options = get_post_meta( $postID, 'f12-cf7-doubleoptin', true );
144
145 if ( ! $options ) {
146 $this->get_logger()->debug( 'No options found for postID, returning defaults', [
147 'plugin' => 'double-opt-in',
148 'post_id' => $postID,
149 ] );
150
151 return $data;
152 }
153
154 $this->get_logger()->debug( 'Options merged with defaults', [
155 'plugin' => 'double-opt-in',
156 'post_id' => $postID,
157 ] );
158
159 return array_merge( $data, $options );
160 }
161
162
163 /**
164 * Private constructor to prevent direct instantiation.
165 */
166 private function __construct() {
167 $this->logger = Logger::getInstance();
168
169 if ( ! get_option( 'f12_cf7_doubleoptin_installed_at' ) ) {
170 update_option( 'f12_cf7_doubleoptin_installed_at', time() );
171 }
172
173 $this->get_logger()->info( 'Initialization of Forge12 Double Opt-In started', [
174 'plugin' => 'double-opt-in',
175 'class' => __CLASS__,
176 'method' => __METHOD__,
177 ] );
178
179 load_plugin_textdomain(
180 'double-opt-in',
181 false,
182 dirname( plugin_basename( __FILE__ ) ) . '/languages'
183 );
184 $this->get_logger()->debug( 'Textdomain loaded', [
185 'plugin' => 'double-opt-in',
186 'domain' => 'double-opt-in',
187 ] );
188
189 do_action( 'f12_cf7_doubleoptin_init', $this );
190 $this->get_logger()->debug( 'Action f12_cf7_doubleoptin_init executed', [
191 'plugin' => 'double-opt-in',
192 ] );
193
194 $this->TemplateHandler = TemplateHandler::getInstance();
195 $this->get_logger()->debug( 'TemplateHandler initialized', [
196 'plugin' => 'double-opt-in',
197 ] );
198
199 $UI = new UI( $this->get_logger(), $this->TemplateHandler, FORGE12_OPTIN_SLUG, 'Forge12 Double Opt-In', 'manage_options' );
200 $this->get_logger()->debug( 'UI initialized', [
201 'plugin' => 'double-opt-in',
202 ] );
203
204 add_action( 'after_setup_theme', array( $this, 'init' ) );
205 $this->get_logger()->debug( 'Hook after_setup_theme registered', [
206 'plugin' => 'double-opt-in',
207 ] );
208
209 $Compatibility = new Compatibility( $this );
210 $this->get_logger()->debug( 'Compatibility initialized', [
211 'plugin' => 'double-opt-in',
212 ] );
213
214 $CleanUp = new CleanUp( $this->get_logger() );
215 $this->get_logger()->debug( 'CleanUp initialized', [
216 'plugin' => 'double-opt-in',
217 ] );
218
219 // Pagination
220 Pagination::getInstance();
221 $this->get_logger()->debug( 'Pagination initialized', [
222 'plugin' => 'double-opt-in',
223 ] );
224
225 // initialize filter
226 CategoryOptions::getInstance();
227 $this->get_logger()->debug( 'CategoryOptions initialized', [
228 'plugin' => 'double-opt-in',
229 ] );
230
231 OptInLimitFilter::getInstance();
232 $this->get_logger()->debug( 'OptInLimitFilter initialized', [
233 'plugin' => 'double-opt-in',
234 ] );
235
236 OptInSearchFilter::getInstance();
237 $this->get_logger()->debug( 'OptInSearchFilter initialized', [
238 'plugin' => 'double-opt-in',
239 ] );
240
241
242 $this->get_logger()->info( 'Initialization of Forge12 Double Opt-In completed', [
243 'plugin' => 'double-opt-in',
244 'class' => __CLASS__,
245 'method' => __METHOD__,
246 ] );
247 }
248
249 public function get_logger() {
250 return $this->logger;
251 }
252
253 /**
254 * Retrieve the template handler instance.
255 *
256 * @return TemplateHandler The template handler instance.
257 */
258 public function get_template_handler() {
259 $this->get_logger()->debug( 'TemplateHandler retrieved', [
260 'plugin' => 'double-opt-in',
261 'class' => __CLASS__,
262 'method' => __METHOD__,
263 ] );
264
265 return $this->TemplateHandler;
266 }
267
268 /**
269 * @private WordPress Hook
270 */
271 public function init() {
272 $this->get_logger()->debug( 'Init started', [
273 'plugin' => 'double-opt-in',
274 'class' => __CLASS__,
275 'method' => __METHOD__,
276 ] );
277
278 do_action( 'f12_cf7_doubleoptin_register_implementations' );
279
280 $this->get_logger()->debug( 'Action f12_cf7_doubleoptin_register_implementations executed', [
281 'plugin' => 'double-opt-in',
282 ] );
283 }
284
285
286 /**
287 * Return the settings for the optin.
288 *
289 * @param string $single The Key of the setting to return only the required setting
290 *
291 * @formatter:off
292 * @return {
293 * // Returns the Settings for the DOI
294 *
295 * @type string $optout_subject The Subject for the OptOut Mail
296 * @type string $optout_body The Content for the OptOut Mail
297 * @type int $optout_page The Post ID for the OptOut Page
298 * @type int $support Defines if the Support link will be added to the footer
299 * @type int $delete An integer from 1 to 30
300 * @type int $delete_unconfirmed An integer from 1 to 30
301 * @type string $delete_period The time period, either months, days, years
302 * @type string $delete_unconfirmed_period The time period, either months, days, years
303 * }
304 * @formatter:on
305 */
306 public function getSettings( $single = '', $container = null ) {
307 $this->get_logger()->debug( 'Fetching settings', [
308 'plugin' => 'double-opt-in',
309 'class' => __CLASS__,
310 'method' => __METHOD__,
311 'single' => $single,
312 'container' => $container,
313 ] );
314
315 $default = array();
316
317 $default = apply_filters( 'f12_cf7_doubleoptin_settings', $default );
318
319 $settings = get_option( 'f12-doi-settings' );
320
321 if ( ! is_array( $settings ) ) {
322 $this->get_logger()->debug( 'No settings found in options, using empty array', [
323 'plugin' => 'double-opt-in',
324 ] );
325 $settings = array();
326 }
327
328 foreach ( $default as $key => $data ) {
329 if ( isset( $settings[ $key ] ) ) {
330 if ( is_array( $default[ $key ] ) ) {
331 $default[ $key ] = array_merge( $default[ $key ], $settings[ $key ] );
332 } else {
333 $default[ $key ] = $settings[ $key ];
334 }
335 $this->get_logger()->debug( 'Merged settings for key', [
336 'plugin' => 'double-opt-in',
337 'key' => $key,
338 ] );
339 }
340 }
341
342 $settings = $default;
343
344 if ( ! empty( $single ) ) {
345 if ( $container != null ) {
346 if ( isset( $settings[ $container ] ) && isset( $settings[ $container ][ $single ] ) ) {
347 $this->get_logger()->debug( 'Returning single setting from container', [
348 'plugin' => 'double-opt-in',
349 'container' => $container,
350 'single' => $single,
351 ] );
352 $settings = $settings[ $container ][ $single ];
353 }
354 }
355 } else {
356 if ( isset( $settings[ $single ] ) ) {
357 $this->get_logger()->debug( 'Returning single setting', [
358 'plugin' => 'double-opt-in',
359 'single' => $single,
360 ] );
361 $settings = $settings[ $single ];
362 }
363 }
364
365 return $settings;
366 }
367 }
368
369
370 add_action( 'plugins_loaded', function () {
371 add_cron_jobs();
372 CF7DoubleOptIn::getInstance();
373 } );
374
375 }