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

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

237 lines 6.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 /**
12 * Class UIPage
13 */
14 abstract class UIPage {
15 /**
16 * @var string
17 */
18 protected $domain;
19 /**
20 * @var string
21 */
22 protected $slug;
23 /**
24 * @var string
25 */
26 protected $title;
27 /**
28 * @var string
29 */
30 protected $class;
31 /**
32 * @var int
33 */
34 protected $position = 0;
35 /**
36 * @var TemplateHandler
37 */
38 protected TemplateHandler $TemplateHandler;
39 private LoggerInterface $logger;
40
41 /**
42 * __construct method initializes an instance of the class.
43 *
44 * @param TemplateHandler $templateHandler - The TemplateHandler object used for handling templates.
45 * @param string $domain - The domain of the current page.
46 * @param string $slug - The WordPress slug used for the current page.
47 * @param string $title - The title of the sidebar.
48 * @param int $position - (optional) The position of the sidebar. Default is 10.
49 * @param string $class - (optional) The class of the sidebar. Default is an empty string.
50 *
51 * @return void
52 */
53 public function __construct( LoggerInterface $logger, TemplateHandler $templateHandler, string $domain, string $slug, string $title, int $position = 10, string $class = '' ) {
54 $this->logger = $logger;
55 $this->TemplateHandler = $templateHandler;
56 $this->domain = $domain;
57 $this->slug = $slug;
58 $this->title = $title;
59 $this->class = $class;
60 $this->position = $position;
61
62 $this->get_logger()->info( 'UIPage class instance created.', [
63 'plugin' => $this->domain,
64 'slug' => $this->slug,
65 'title' => $this->title,
66 'position' => $this->position,
67 ] );
68
69 add_filter( 'f12_cf7_doubleoptin_settings', array( $this, 'getSettings' ) );
70 $this->get_logger()->debug( 'Added "getSettings" method to "f12_cf7_doubleoptin_settings" filter.', [
71 'plugin' => $this->domain,
72 ] );
73 }
74
75 public function get_logger() {
76 return $this->logger;
77 }
78
79 public function hideInMenu() {
80 return false;
81 }
82
83 public function getPosition() {
84 return $this->position;
85 }
86
87 public function isDashboard() {
88 return $this->getPosition() == 0;
89 }
90
91 public function getDomain() {
92 return $this->domain;
93 }
94
95 public function getSlug() {
96 return $this->slug;
97 }
98
99 public function getTitle() {
100 return $this->title;
101 }
102
103 public function getClass() {
104 return $this->class;
105 }
106
107 /**
108 * @param $settings
109 *
110 * @return mixed
111 */
112 public abstract function getSettings( $settings );
113
114 /**
115 * @param string $slug - The WordPress Slug
116 * @param string $page - The Name of the current Page e.g.: license
117 *
118 * @return void
119 */
120 protected abstract function theSidebar( $slug, $page );
121
122 /**
123 * @param string $slug - The WordPress Slug
124 * @param string $page - The Name of the current Page e.g.: license
125 *
126 * @return void
127 */
128 protected abstract function theContent( $slug, $page, $settings );
129
130 /**
131 * @return void
132 * @private WordPress HOOK
133 */
134 public function renderContent( $slug, $page ) {
135 $this->get_logger()->info( 'Attempting to render content for page: ' . $page, [
136 'plugin' => $this->domain,
137 'handler_slug' => $this->slug,
138 ] );
139
140 if ( $this->slug != $page ) {
141 $this->get_logger()->debug( 'Skipping content rendering because the provided page slug does not match the handler\'s slug.', [
142 'plugin' => $this->domain,
143 'provided_slug' => $page,
144 'handler_slug' => $this->slug,
145 ] );
146 return;
147 }
148
149 $settings = CF7DoubleOptIn::getInstance()->getSettings();
150
151 // Output all pending messages (e.g., success, error)
152 $messages_html = Messages::getInstance()->getAll();
153 if (!empty($messages_html)) {
154 $this->get_logger()->notice( 'Rendering message box with content.', [
155 'plugin' => $this->domain,
156 ] );
157 }
158 echo esc_html( $messages_html );
159
160 // Trigger actions before the main content box
161 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $page . '_before_box" action.', [
162 'plugin' => $this->domain,
163 ] );
164 do_action( 'f12_cf7_doubleoptin_ui_' . $page . '_before_box' );
165
166 // Start of the main content box
167 ?>
168 <div class="box">
169 <?php
170 // Trigger actions before the main content
171 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $page . '_before_content" action.', [
172 'plugin' => $this->domain,
173 ] );
174 do_action( 'f12_cf7_doubleoptin_ui_' . $page . '_before_content', $settings );
175
176 // Render the actual page content
177 $this->get_logger()->info( 'Calling theContent() method to render the page\'s main content.', [
178 'plugin' => $this->domain,
179 ] );
180 $this->theContent( $slug, $page, $settings );
181
182 // Trigger actions after the main content
183 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $page . '_after_content" action.', [
184 'plugin' => $this->domain,
185 ] );
186 do_action( 'f12_cf7_doubleoptin_ui_' . $page . '_after_content', $settings );
187 ?>
188 </div>
189 <?php
190
191 // Trigger actions after the main content box
192 $this->get_logger()->info( 'Triggering "f12_cf7_doubleoptin_ui_' . $page . '_after_box" action.', [
193 'plugin' => $this->domain,
194 ] );
195 do_action( 'f12_cf7_doubleoptin_ui_' . $page . '_after_box' );
196
197 $this->get_logger()->notice( 'Content rendering for page ' . $page . ' completed successfully.', [
198 'plugin' => $this->domain,
199 ] );
200 }
201
202 /**
203 * @param string $slug
204 * @param string $page
205 *
206 * @return void
207 * @private WordPress Hook
208 */
209 public function renderSidebar( $slug, $page ) {
210 $this->get_logger()->info( 'Attempting to render sidebar content for page: ' . $page, [
211 'plugin' => $this->domain,
212 'handler_slug' => $this->slug,
213 ] );
214
215 // Check if the current page slug matches the one handled by this class
216 if ( $this->slug != $page ) {
217 $this->get_logger()->debug( 'Skipping sidebar rendering because the provided page slug does not match the handler\'s slug.', [
218 'plugin' => $this->domain,
219 'provided_slug' => $page,
220 'handler_slug' => $this->slug,
221 ] );
222 return;
223 }
224
225 $this->get_logger()->info( 'Calling theSidebar() method to render the page\'s sidebar content.', [
226 'plugin' => $this->domain,
227 ] );
228
229 // Call the method responsible for generating the sidebar's content
230 $this->theSidebar( $slug, $page );
231
232 $this->get_logger()->notice( 'Sidebar rendering for page ' . $page . ' completed successfully.', [
233 'plugin' => $this->domain,
234 ] );
235 }
236 }
237 }