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 / ui / UISettings.class.php

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

315 lines 11.5 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 /**
12 * Class UIDashboard
13 *
14 * @package forge12\contactform7\CF7DoubleOptIn
15 */
16 class UISettings extends UIPageForm {
17 /**
18 * Class constructor.
19 *
20 * @param TemplateHandler $templateHandler The template handler object used for rendering.
21 * @param string $domain The domain for the settings object.
22 *
23 * @return void
24 */
25 public function __construct( LoggerInterface $logger, TemplateHandler $templateHandler, string $domain ) {
26
27 parent::__construct( $logger, $templateHandler, $domain, 'settings', __( 'Settings', 'double-opt-in' ) );
28
29 $this->get_logger()->notice( 'UIPageSettings parent constructor called with default position.', [
30 'plugin' => $domain,
31 ] );
32 }
33
34 /**
35 * Render the license subpage content
36 */
37 protected function theContent( $slug, $page, $settings ) {
38 $this->get_logger()->info( 'Rendering the main content for the "Settings" UI page.', [
39 'plugin' => $this->domain,
40 'page_slug' => $page,
41 ] );
42
43 // Define the options for the time period dropdowns.
44 $deleteOptionItems = array( 0 => __( 'never', 'double-opt-in' ) );
45 for ( $i = 1; $i <= 30; $i ++ ) {
46 $deleteOptionItems[ $i ] = (string) $i;
47 }
48
49 $deleteOptionPeriod = array(
50 'months' => 'months',
51 'days' => 'days',
52 'years' => 'years'
53 );
54
55 echo Messages::getInstance()->getAll();
56
57 // The form tag is handled by the parent renderContent method
58 ?>
59 <h2>
60 <?php _e( 'Settings', 'double-opt-in' ); ?>
61 </h2>
62
63 <div class="option">
64 <div class="label">
65 <label for="delete"><?php _e( 'Delete Opt-Ins', 'double-opt-in' ); ?></label>
66 </div>
67 <div class="input">
68 <select id="delete" name="delete">
69 <?php
70 foreach ( $deleteOptionItems as $value => $label ):
71 $selected = ( $value == $settings['delete'] ) ? 'selected="selected"' : '';
72 ?>
73 <option value="<?php echo esc_attr( $value ); ?>" <?php echo $selected; ?>>
74 <?php echo esc_html( $label ); ?>
75 </option>
76 <?php endforeach; ?>
77 </select>
78
79 <select id="delete_period" name="delete_period">
80 <?php
81 foreach ( $deleteOptionPeriod as $key => $label ):
82 $selected = ( $key == $settings['delete_period'] ) ? 'selected="selected"' : '';
83 ?>
84 <option value="<?php echo esc_attr( $key ); ?>" <?php echo $selected; ?>>
85 <?php echo esc_html( $label ); ?>
86 </option>
87 <?php endforeach; ?>
88 </select>
89
90 <p>
91 <?php _e( 'Select the period of time after which all data will be deleted automatically. As for the european GDPR it is recommend to use the smallest period of time as possible.', 'double-opt-in' ); ?>
92 </p>
93 </div>
94 </div>
95
96 <div class="option">
97 <div class="label">
98 <label for="delete_unconfirmed"><?php _e( 'Delete unconfirmed Opt-Ins', 'double-opt-in' ); ?></label>
99 </div>
100 <div class="input">
101 <select id="delete_unconfirmed" name="delete_unconfirmed">
102 <?php
103 foreach ( $deleteOptionItems as $value => $label ):
104 $selected = ( $value == $settings['delete_unconfirmed'] ) ? 'selected="selected"' : '';
105 ?>
106 <option value="<?php echo esc_attr( $value ); ?>" <?php echo $selected; ?>>
107 <?php echo esc_html( $label ); ?>
108 </option>
109 <?php endforeach; ?>
110 </select>
111
112 <select id="delete_unconfirmed_period" name="delete_unconfirmed_period">
113 <?php
114 foreach ( $deleteOptionPeriod as $key => $label ):
115 $selected = ( $key == $settings['delete_unconfirmed_period'] ) ? 'selected="selected"' : '';
116 ?>
117 <option value="<?php echo esc_attr( $key ); ?>" <?php echo $selected; ?>>
118 <?php echo esc_html( $label ); ?>
119 </option>
120 <?php endforeach; ?>
121 </select>
122 <p>
123 <?php _e( 'Select the period of time after which all unconfirmed data will be deleted automatically. As for the european GDPR it is recommend to use the smallest period of time as possible.', 'double-opt-in' ); ?>
124 </p>
125 </div>
126 </div>
127
128 <div class="option">
129 <div class="label">
130 <label for="telemetry"><?php _e( 'Telemetry', 'double-opt-in' ); ?></label>
131 </div>
132 <div class="input">
133 <div class="toggle-item-wrapper">
134 <!-- TOGGLE -->
135 <div class="f12-checkbox-toggle">
136 <div class="toggle-container">
137 <?php
138 $field_name = 'telemetry';
139 // Default = aktiv (1), nur wenn explizit 0 → deaktiviert
140 echo sprintf(
141 '<input name="%s" type="hidden" value="%s" id="%s" class="toggle" data-before="%s" data-after="%s">',
142 esc_attr( $field_name ),
143 esc_attr( $settings[$field_name] ?? 1 ),
144 esc_attr( $field_name ),
145 esc_attr__( 'On', 'double-opt-in' ),
146 esc_attr__( 'Off', 'double-opt-in' )
147 );
148
149
150 ?>
151 <label for="<?php esc_attr_e( $field_name ); ?>"
152 class="toggle-label"></label>
153 </div>
154 <label for="<?php esc_attr_e( $field_name ); ?>">
155 <?php _e( 'Enable this option to allow anonymous telemetry data to be sent. This helps us improve and develop the plugin.', 'double-opt-in' ); ?>
156 </label>
157 <label class="overlay" for="<?php esc_attr_e( $field_name ); ?>"></label>
158 </div>
159 </div>
160 </div>
161 </div>
162 <?php
163 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_settings_render" action.', [
164 'plugin' => $this->domain,
165 ] );
166
167 do_action( 'f12_cf7_doubleoptin_ui_settings_render', $settings );
168
169 $this->get_logger()->notice( 'Settings page content rendered successfully.', [
170 'plugin' => $this->domain,
171 ] );
172 }
173
174 /**
175 * Display the sidebar content for the specified page.
176 *
177 * @param string $slug The slug of the current page.
178 * @param string $page The current page.
179 *
180 * @return void
181 */
182 protected function theSidebar( $slug, $page ) {
183 $this->get_logger()->info( 'Attempting to render the sidebar for the "settings" page.', [
184 'plugin' => $this->domain,
185 'page_slug' => $page,
186 ] );
187
188 // Check if the current page is the 'settings' page, and return if it's not.
189 if ( $page != 'settings' ) {
190 $this->get_logger()->debug( 'Skipping sidebar rendering because the page is not "settings".', [
191 'plugin' => $this->domain,
192 'page_slug' => $page,
193 ] );
194
195 return;
196 }
197
198 $this->get_logger()->notice( 'Rendering sidebar content for the "settings" page.', [
199 'plugin' => $this->domain,
200 ] );
201 ?>
202 <div class="box">
203 <h2>
204 <?php _e( 'Hint:', 'double-opt-in' ); ?>
205 </h2>
206 <p>
207 <?php _e( "In the table on the left side, you'll find an list global settings. They will affect all forms using the double opt-in.", 'double-opt-in' ); ?>
208 </p>
209 </div>
210 <?php
211 $this->get_logger()->notice( 'Sidebar for the "settings" page rendered successfully.', [
212 'plugin' => $this->domain,
213 ] );
214 }
215
216 /**
217 * Retrieves the settings array.
218 *
219 * @param array $settings The existing settings array.
220 *
221 * @return array The updated settings array.
222 */
223 public function getSettings( $settings ) {
224 $this->get_logger()->info( 'getSettings method called. Merging default settings with existing ones.', [
225 'plugin' => $this->domain,
226 'page_slug' => $this->slug,
227 ] );
228
229 // Define the default settings for this page.
230 $default_settings = array(
231 'telemetry' => 1,
232 'delete' => 0,
233 'delete_unconfirmed' => 7,
234 'delete_period' => 'months',
235 'delete_unconfirmed_period' => 'months',
236 );
237
238 // Merge the default settings with the provided settings array.
239 // This ensures that default values exist if they are not already set.
240 $settings = array_merge( $settings, $default_settings );
241
242 $this->get_logger()->debug( 'Merged settings: ' . json_encode( $settings ), [
243 'plugin' => $this->domain,
244 ] );
245
246 return $settings;
247 }
248
249 /**
250 * Update the settings based on the POST data.
251 *
252 * @param array $settings The current settings.
253 *
254 * @return array The updated settings.
255 */
256 protected function onSave( $settings ) {
257 $this->get_logger()->info( 'Executing onSave method for the "Settings" UI page.', [
258 'plugin' => $this->domain,
259 ] );
260
261 // Update the 'delete' setting if it exists in the POST data.
262 if ( isset( $_POST['delete'] ) ) {
263 $settings['delete'] = (int) $_POST['delete'];
264 $this->get_logger()->debug( 'Updated "delete" setting to: ' . $settings['delete'], [
265 'plugin' => $this->domain,
266 ] );
267 }
268
269 // Update the 'delete_unconfirmed' setting if it exists in the POST data.
270 if ( isset( $_POST['delete_unconfirmed'] ) ) {
271 $settings['delete_unconfirmed'] = (int) $_POST['delete_unconfirmed'];
272 $this->get_logger()->debug( 'Updated "delete_unconfirmed" setting to: ' . $settings['delete_unconfirmed'], [
273 'plugin' => $this->domain,
274 ] );
275 }
276
277 if ( isset( $_POST['telemetry'] ) ) {
278 $settings['telemetry'] = (int) $_POST['telemetry'];
279 $this->get_logger()->debug( 'Updated "telemetry" setting to: ' . $settings['telemetry'], [
280 'plugin' => $this->domain,
281 ] );
282 } else {
283 // If the checkbox is not set, it means the user unchecked it, so set the value to 0.
284 $settings['telemetry'] = 0;
285 $this->get_logger()->debug( 'Updated "telemetry" setting to 0 (unchecked).', [
286 'plugin' => $this->domain,
287 ] );
288 }
289
290 // Update the 'delete_period' setting, sanitizing the input as a string.
291 if ( isset( $_POST['delete_period'] ) ) {
292 $settings['delete_period'] = sanitize_text_field( $_POST['delete_period'] );
293 $this->get_logger()->debug( 'Updated "delete_period" setting to: ' . $settings['delete_period'], [
294 'plugin' => $this->domain,
295 ] );
296 }
297
298 // Update the 'delete_unconfirmed_period' setting, sanitizing the input as a string.
299 if ( isset( $_POST['delete_unconfirmed_period'] ) ) {
300 $settings['delete_unconfirmed_period'] = sanitize_text_field( $_POST['delete_unconfirmed_period'] );
301 $this->get_logger()->debug( 'Updated "delete_unconfirmed_period" setting to: ' . $settings['delete_unconfirmed_period'], [
302 'plugin' => $this->domain,
303 ] );
304 }
305
306 $this->get_logger()->notice( 'onSave method finished. Returning the updated settings array.', [
307 'plugin' => $this->domain,
308 'final_settings' => $settings,
309 ] );
310
311 // Return the updated settings array to be saved.
312 return $settings;
313 }
314 }
315 }