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.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 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 All 38 releases
← All changes | compatibility/cf7/CF7ConditionalFields.class.php +130 -58 3.0.71 → 5.5.0 View file →
@@ -1,69 +1,141 @@
1 1 <?php
2 2
3 3 namespace forge12\contactform7\CF7DoubleOptIn {
4 - if (!defined('ABSPATH')) {
5 - exit;
6 - }
7 4
5 + use Forge12\Shared\LoggerInterface;
8 6
9 - /**
10 - * Class ConditionalFields Support
11 - * Add support for conditional fields if available.
12 - *
13 - * @package forge12\contactform7\CF7DoubleOptIn
14 - */
15 - class CF7ConditionalFields
16 - {
17 - private $conditionalFieldsParameter = array(
18 - '_wpcf7cf_hidden_group_fields' => '',
19 - '_wpcf7cf_hidden_groups' => '',
20 - '_wpcf7cf_visible_groups' => '',
21 - '_wpcf7cf_repeaters' => '',
22 - '_wpcf7cf_steps' => '',
23 - '_wpcf7cf_options' => ''
24 - );
7 + if ( ! defined( 'ABSPATH' ) ) {
8 + exit;
9 + }
25 10
26 - /**
27 - * Admin constructor.
28 - */
29 - public function __construct()
30 - {
31 - add_filter('f12_cf7_doubleoptin_add_request_parameter', array($this,'_initConditionalFieldParameter'), 10, 1);
32 - add_filter('f12_cf7_doubleoptin_body', array($this, '_getOptinBody'), 10, 1);
33 - }
34 11
35 - /**
36 - * Add the option to add conditional fields also to the optin mail.
37 - * @return string
38 - */
39 - public function _getOptinBody($body)
40 - {
41 - if(!defined('WPCF7CF_PLUGIN') || !class_exists('\Wpcf7cfMailParser')){
42 - return $body;
43 - }
12 + /**
13 + * Class ConditionalFields Support
14 + * Add support for conditional fields if available.
15 + *
16 + * @package forge12\contactform7\CF7DoubleOptIn
17 + */
18 + class CF7ConditionalFields {
19 + private $conditionalFieldsParameter = array(
20 + '_wpcf7cf_hidden_group_fields' => '',
21 + '_wpcf7cf_hidden_groups' => '',
22 + '_wpcf7cf_visible_groups' => '',
23 + '_wpcf7cf_repeaters' => '',
24 + '_wpcf7cf_steps' => '',
25 + '_wpcf7cf_options' => ''
26 + );
27 + private LoggerInterface $logger;
44 28
45 - $CFMP = new \Wpcf7cfMailParser($body, $this->conditionalFieldsParameter['_wpcf7cf_visible_groups'], $this->conditionalFieldsParameter['_wpcf7cf_hidden_groups'], $this->conditionalFieldsParameter['_wpcf7cf_repeaters'], array());
46 - return $CFMP->getParsedMail();
47 - }
29 + /**
30 + * Admin constructor.
31 + */
32 + public function __construct( LoggerInterface $logger ) {
33 + $this->logger = $logger;
48 34
49 - /**
50 - * Check if conditional field plugin is available and if yes, check for the parameter
51 - * which has to be stored within the content.
52 - * @param $parameter
53 - */
54 - public function _initConditionalFieldParameter($parameter)
55 - {
56 - if (!defined('WPCF7CF_PLUGIN')) {
57 - return $parameter;
58 - }
35 + $this->get_logger()->debug( 'Conditional fields constructor called', [
36 + 'plugin' => 'double-opt-in',
37 + 'class' => __CLASS__,
38 + 'method' => __METHOD__,
39 + ] );
59 40
60 - foreach ($this->conditionalFieldsParameter as $key => $value) {
61 - if (isset($_POST[$key])) {
62 - $parameter[$key] = sanitize_text_field($_POST[$key]);
63 - $this->conditionalFieldsParameter[$key] = sanitize_text_field(json_decode(stripslashes($_POST[$key])));
64 - }
65 - }
66 - return $parameter;
67 - }
68 - }
41 + add_filter(
42 + 'f12_cf7_doubleoptin_add_request_parameter',
43 + [ $this, '_initConditionalFieldParameter' ],
44 + 10,
45 + 1
46 + );
47 + $this->get_logger()->debug( 'Filter f12_cf7_doubleoptin_add_request_parameter registered', [
48 + 'plugin' => 'double-opt-in',
49 + ] );
50 +
51 + add_filter(
52 + 'f12_cf7_doubleoptin_body',
53 + [ $this, '_getOptinBody' ],
54 + 10,
55 + 1
56 + );
57 + $this->get_logger()->debug( 'Filter f12_cf7_doubleoptin_body registered', [
58 + 'plugin' => 'double-opt-in',
59 + ] );
60 + }
61 +
62 +
63 + public function get_logger() {
64 + return $this->logger;
65 + }
66 +
67 + /**
68 + * Add the option to add conditional fields also to the optin mail.
69 + *
70 + * @return string
71 + */
72 + public function _getOptinBody( $body ) {
73 + $this->get_logger()->debug( '_getOptinBody called', [
74 + 'plugin' => 'double-opt-in',
75 + 'class' => __CLASS__,
76 + 'method' => __METHOD__,
77 + ] );
78 +
79 + if ( ! defined( 'WPCF7CF_PLUGIN' ) || ! class_exists( '\Wpcf7cfMailParser' ) ) {
80 + $this->get_logger()->debug( 'Conditional fields plugin not available, returning original body', [
81 + 'plugin' => 'double-opt-in',
82 + ] );
83 + return $body;
84 + }
85 +
86 + $CFMP = new \Wpcf7cfMailParser(
87 + $body,
88 + $this->conditionalFieldsParameter['_wpcf7cf_visible_groups'],
89 + $this->conditionalFieldsParameter['_wpcf7cf_hidden_groups'],
90 + $this->conditionalFieldsParameter['_wpcf7cf_repeaters'],
91 + []
92 + );
93 +
94 + $parsedBody = $CFMP->getParsedMail();
95 +
96 + $this->get_logger()->debug( 'Optin body parsed with conditional fields', [
97 + 'plugin' => 'double-opt-in',
98 + ] );
99 +
100 + return $parsedBody;
101 + }
102 +
103 +
104 + /**
105 + * Check if conditional field plugin is available and if yes, check for the parameter
106 + * which has to be stored within the content.
107 + *
108 + * @param $parameter
109 + */
110 + public function _initConditionalFieldParameter( $parameter ) {
111 + $this->get_logger()->debug( '_initConditionalFieldParameter called', [
112 + 'plugin' => 'double-opt-in',
113 + 'class' => __CLASS__,
114 + 'method' => __METHOD__,
115 + ] );
116 +
117 + if ( ! defined( 'WPCF7CF_PLUGIN' ) ) {
118 + $this->get_logger()->debug( 'Conditional fields plugin not available, returning parameter unchanged', [
119 + 'plugin' => 'double-opt-in',
120 + ] );
121 + return $parameter;
122 + }
123 +
124 + foreach ( $this->conditionalFieldsParameter as $key => $value ) {
125 + if ( isset( $_POST[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
126 + $parameter[ $key ] = sanitize_text_field( $_POST[ $key ] );
127 + $this->conditionalFieldsParameter[ $key ] = sanitize_text_field(
128 + json_decode( wp_unslash( $_POST[ $key ] ) )
129 + );
130 +
131 + $this->get_logger()->debug( 'Conditional field parameter set', [
132 + 'plugin' => 'double-opt-in',
133 + 'key' => $key,
134 + ] );
135 + }
136 + }
137 +
138 + return $parameter;
139 + }
140 + }
69 141 }