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 / core / UIPageForm.class.php

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

206 lines 6.7 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 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 abstract class UIPageForm extends UIPage {
9 /**
10 * define if the button for the submit should be displayed or not.
11 * if hidden, the wp_nonce will also be removed. Ensure you handle
12 * the save process on your own. The onSave function will still be called
13 *
14 * @var bool
15 */
16 private $hide_submit_button = false;
17
18 /**
19 * @return mixed
20 */
21 protected function maybeSave() {
22 $this->get_logger()->info( 'Attempting to save settings.', [
23 'plugin' => $this->domain,
24 'page_slug' => $this->slug,
25 ] );
26
27 // Check for the nonce and verify it for security
28 if ( isset( $_POST['doi_settings_nonce'] ) && wp_verify_nonce( $_POST['doi_settings_nonce'], 'doi_settings_action' ) ) {
29 $this->get_logger()->notice( 'Nonce verification successful. Proceeding with save.', [
30 'plugin' => $this->domain,
31 ] );
32
33 $settings = CF7DoubleOptIn::getInstance()->getSettings();
34 $this->get_logger()->debug( 'Current settings retrieved.', [
35 'plugin' => $this->domain,
36 'settings' => $settings,
37 ] );
38
39 // Apply a filter before the save operation
40 $this->get_logger()->info( 'Applying "f12_cf7_doubleoptin_ui_' . $this->slug . '_before_on_save" filter.', [
41 'plugin' => $this->domain,
42 ] );
43 $settings = apply_filters( 'f12_cf7_doubleoptin_ui_' . $this->slug . '_before_on_save', $settings );
44
45 // Call the main save method
46 $this->get_logger()->info( 'Calling the onSave method to process and update settings.', [
47 'plugin' => $this->domain,
48 ] );
49 $settings = $this->onSave( $settings );
50
51 // Apply a filter after the save operation
52 $this->get_logger()->info( 'Applying "f12_cf7_doubleoptin_ui_' . $this->slug . '_after_on_save" filter.', [
53 'plugin' => $this->domain,
54 ] );
55 $settings = apply_filters( 'f12_cf7_doubleoptin_ui_' . $this->slug . '_after_on_save', $settings );
56
57 // Save the settings to the database
58 $this->get_logger()->notice( 'Calling the save method to persist the changes.', [
59 'plugin' => $this->domain,
60 ] );
61 $this->save( $settings );
62
63 // Add a success message
64 Messages::getInstance()->add( __( 'Settings updated', 'double-opt-in' ), 'success' );
65 $this->get_logger()->info( 'Success message added to the queue.', [
66 'plugin' => $this->domain,
67 ] );
68
69 } else {
70 $this->get_logger()->error( 'Nonce verification failed. Settings not saved.', [
71 'plugin' => $this->domain,
72 'post_data_present' => isset($_POST['doi_settings_nonce']),
73 'nonce_value' => $_POST['doi_settings_nonce'] ?? 'not set',
74 ] );
75 }
76 }
77
78 /**
79 * Save the settings.
80 *
81 * @param array $settings The settings to be saved.
82 *
83 * @return void
84 * @private WordPress HOOK
85 */
86 protected function save( array $settings ) {
87 $this->get_logger()->info( 'Saving settings to the database.', [
88 'plugin' => $this->domain,
89 'page_slug' => $this->slug,
90 ] );
91
92 // Update the 'f12-doi-settings' option with the new settings array
93 update_option( 'f12-doi-settings', $settings );
94 $this->get_logger()->notice( 'Settings successfully updated in the database.', [
95 'plugin' => $this->domain,
96 'option_name' => 'f12-doi-settings',
97 ] );
98
99 // Trigger a custom action after the save operation is complete
100 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $this->slug . '_after_save" action.', [
101 'plugin' => $this->domain,
102 ] );
103 do_action( 'f12_cf7_doubleoptin_ui_' . $this->slug . '_after_save', $settings );
104 }
105
106 /**
107 * Option to hide the submit button
108 *
109 * @param bool $hide
110 *
111 * @return void
112 */
113 protected function hideSubmitButton( $hide ) {
114 $this->hide_submit_button = $hide;
115 }
116
117 /**
118 * Returns true if the button should be hidden.
119 *
120 * @return bool
121 */
122 protected function isSubmitButtonHidden() {
123 return $this->hide_submit_button;
124 }
125
126 /**
127 * Update the settings and return them
128 *
129 * @param $settings
130 *
131 * @return array
132 */
133 protected abstract function onSave( $settings );
134
135 /**
136 * @return void
137 * @private WordPress HOOK
138 */
139 public function renderContent( $slug, $page ) {
140 $this->get_logger()->info( 'Attempting to render content for page: ' . $page, [
141 'plugin' => $this->domain,
142 'handler_slug' => $this->slug,
143 ] );
144
145 if ( $this->slug != $page ) {
146 $this->get_logger()->debug( 'Skipping content rendering because the provided page slug does not match the handler\'s slug.', [
147 'plugin' => $this->domain,
148 'provided_slug' => $page,
149 'handler_slug' => $this->slug,
150 ] );
151 return;
152 }
153
154 $this->maybeSave();
155 $settings = CF7DoubleOptIn::getInstance()->getSettings();
156
157 $messages_html = Messages::getInstance()->getAll();
158 if (!empty($messages_html)) {
159 $this->get_logger()->notice( 'Rendering message box with content.', [
160 'plugin' => $this->domain,
161 ] );
162 }
163 echo wp_kses_post( $messages_html );
164 ?>
165 <div class="box">
166 <form action="" method="post">
167 <?php
168 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $page . '_before_content" action.', [
169 'plugin' => $this->domain,
170 ] );
171 do_action( 'f12_cf7_doubleoptin_ui_' . $page . '_before_content', $settings );
172
173 $this->get_logger()->info( 'Calling theContent() method to render the page\'s main content.', [
174 'plugin' => $this->domain,
175 ] );
176 $this->theContent( $slug, $page, $settings );
177
178 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $page . '_after_content" action.', [
179 'plugin' => $this->domain,
180 ] );
181 do_action( 'f12_cf7_doubleoptin_ui_' . $page . '_after_content', $settings );
182
183 if ( ! $this->isSubmitButtonHidden() ):
184 $this->get_logger()->debug( 'Submit button is not hidden. Rendering nonce field and submit button.', [
185 'plugin' => $this->domain,
186 ] );
187 wp_nonce_field( 'doi_settings_action', 'doi_settings_nonce' );
188 ?>
189 <input type="submit" name="doubleoptin-settings-submit" class="button button-primary"
190 value=" <?php _e( 'Save', 'double-opt-in' ); ?>"/>
191 <?php
192 else:
193 $this->get_logger()->debug( 'Submit button is hidden. Not rendering.', [
194 'plugin' => $this->domain,
195 ] );
196 endif;
197 ?>
198 </form>
199 </div>
200 <?php
201 $this->get_logger()->notice( 'Content rendering for page ' . $page . ' completed successfully.', [
202 'plugin' => $this->domain,
203 ] );
204 }
205 }
206 }