PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.9
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.9
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / admin / popup-builder / class-popup-settings.php

class-popup-settings.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.9, at inc/admin/popup-builder/class-popup-settings.php

539 lines 25.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MasterAddons\Inc\Admin\PopupBuilder;
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 class Popup_Settings {
9
10 private $default_settings = [];
11
12 public function __construct() {
13 $this->init_default_settings();
14 }
15
16 private function init_default_settings() {
17 $this->default_settings = [
18 'general' => [
19 'enable_popups' => true,
20 'load_assets_globally' => false,
21 'debug_mode' => false,
22 'analytics_tracking' => true,
23 ],
24 'appearance' => [
25 'default_animation' => 'fade',
26 'animation_duration' => 400,
27 'overlay_color' => 'rgba(0, 0, 0, 0.7)',
28 'close_button_position' => 'top-right',
29 'close_button_style' => 'icon',
30 'z_index' => 999999,
31 ],
32 'behavior' => [
33 'prevent_scroll' => true,
34 'close_on_overlay_click' => true,
35 'close_on_esc_key' => true,
36 'auto_focus' => true,
37 'mobile_behavior' => 'responsive',
38 ],
39 'advanced' => [
40 'cookie_expiration' => 30,
41 'test_mode' => false,
42 'test_mode_ips' => '',
43 'disable_on_mobile' => false,
44 'custom_css' => '',
45 'custom_js' => '',
46 ],
47 'integrations' => [
48 'google_analytics' => false,
49 'google_analytics_event' => 'popup_view',
50 'facebook_pixel' => false,
51 'facebook_pixel_event' => 'ViewContent',
52 'mailchimp_api' => '',
53 'mailchimp_list_id' => '',
54 ],
55 'performance' => [
56 'lazy_load' => true,
57 'preload_fonts' => false,
58 'minify_css' => true,
59 'minify_js' => true,
60 'cache_duration' => 3600,
61 ]
62 ];
63 }
64
65 public function get_settings($section = null) {
66 $saved_settings = get_option('jltma_popup_settings', []);
67 $settings = wp_parse_args($saved_settings, $this->default_settings);
68
69 if ($section && isset($settings[$section])) {
70 return $settings[$section];
71 }
72
73 return $settings;
74 }
75
76 public function save_settings($settings) {
77 $current_settings = $this->get_settings();
78 $updated_settings = wp_parse_args($settings, $current_settings);
79
80 return update_option('jltma_popup_settings', $updated_settings);
81 }
82
83 public function render_settings_page() {
84 if (isset($_POST['jltma_popup_settings_nonce'])) {
85 if (wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['jltma_popup_settings_nonce'] ) ), 'jltma_popup_settings')) {
86 $this->process_settings_save();
87 }
88 }
89
90 $settings = $this->get_settings();
91 ?>
92 <div class="wrap ma-popup-settings">
93 <h1><?php esc_html_e('Popup Settings', 'master-addons'); ?></h1>
94
95 <form method="post" action="">
96 <div class="ma-settings-tabs">
97 <ul class="ma-tabs-nav">
98 <li class="active"><a href="#general"><?php esc_html_e('General', 'master-addons'); ?></a></li>
99 <li><a href="#appearance"><?php esc_html_e('Appearance', 'master-addons'); ?></a></li>
100 <li><a href="#behavior"><?php esc_html_e('Behavior', 'master-addons'); ?></a></li>
101 <li><a href="#advanced"><?php esc_html_e('Advanced', 'master-addons'); ?></a></li>
102 <li><a href="#integrations"><?php esc_html_e('Integrations', 'master-addons'); ?></a></li>
103 <li><a href="#performance"><?php esc_html_e('Performance', 'master-addons'); ?></a></li>
104 </ul>
105
106 <div class="ma-tabs-content">
107 <?php $this->render_general_settings($settings['general']); ?>
108 <?php $this->render_appearance_settings($settings['appearance']); ?>
109 <?php $this->render_behavior_settings($settings['behavior']); ?>
110 <?php $this->render_advanced_settings($settings['advanced']); ?>
111 <?php $this->render_integrations_settings($settings['integrations']); ?>
112 <?php $this->render_performance_settings($settings['performance']); ?>
113 </div>
114 </div>
115
116 <?php wp_nonce_field('jltma_popup_settings', 'jltma_popup_settings_nonce'); ?>
117 <p class="submit">
118 <button type="submit" class="button button-primary">
119 <?php esc_html_e('Save Settings', 'master-addons'); ?>
120 </button>
121 </p>
122 </form>
123 </div>
124 <?php
125 }
126
127 private function render_general_settings($settings) {
128 ?>
129 <div id="general" class="ma-tab-pane active">
130 <h2><?php esc_html_e('General Settings', 'master-addons'); ?></h2>
131
132 <table class="form-table">
133 <tr>
134 <th scope="row"><?php esc_html_e('Enable Popups', 'master-addons'); ?></th>
135 <td>
136 <label>
137 <input type="checkbox" name="settings[general][enable_popups]"
138 value="1" <?php checked($settings['enable_popups'], true); ?>>
139 <?php esc_html_e('Enable popup functionality on your site', 'master-addons'); ?>
140 </label>
141 </td>
142 </tr>
143 <tr>
144 <th scope="row"><?php esc_html_e('Load Assets', 'master-addons'); ?></th>
145 <td>
146 <label>
147 <input type="checkbox" name="settings[general][load_assets_globally]"
148 value="1" <?php checked($settings['load_assets_globally'], true); ?>>
149 <?php esc_html_e('Load popup assets on all pages (recommended for better performance)', 'master-addons'); ?>
150 </label>
151 </td>
152 </tr>
153 <tr>
154 <th scope="row"><?php esc_html_e('Debug Mode', 'master-addons'); ?></th>
155 <td>
156 <label>
157 <input type="checkbox" name="settings[general][debug_mode]"
158 value="1" <?php checked($settings['debug_mode'], true); ?>>
159 <?php esc_html_e('Enable debug mode for troubleshooting', 'master-addons'); ?>
160 </label>
161 </td>
162 </tr>
163 <tr>
164 <th scope="row"><?php esc_html_e('Analytics Tracking', 'master-addons'); ?></th>
165 <td>
166 <label>
167 <input type="checkbox" name="settings[general][analytics_tracking]"
168 value="1" <?php checked($settings['analytics_tracking'], true); ?>>
169 <?php esc_html_e('Track popup views and conversions', 'master-addons'); ?>
170 </label>
171 </td>
172 </tr>
173 </table>
174 </div>
175 <?php
176 }
177
178 private function render_appearance_settings($settings) {
179 ?>
180 <div id="appearance" class="ma-tab-pane">
181 <h2><?php esc_html_e('Appearance Settings', 'master-addons'); ?></h2>
182
183 <table class="form-table">
184 <tr>
185 <th scope="row"><?php esc_html_e('Default Animation', 'master-addons'); ?></th>
186 <td>
187 <select name="settings[appearance][default_animation]">
188 <option value="fade" <?php selected($settings['default_animation'], 'fade'); ?>>
189 <?php esc_html_e('Fade', 'master-addons'); ?>
190 </option>
191 <option value="slide-down" <?php selected($settings['default_animation'], 'slide-down'); ?>>
192 <?php esc_html_e('Slide Down', 'master-addons'); ?>
193 </option>
194 <option value="slide-up" <?php selected($settings['default_animation'], 'slide-up'); ?>>
195 <?php esc_html_e('Slide Up', 'master-addons'); ?>
196 </option>
197 <option value="zoom" <?php selected($settings['default_animation'], 'zoom'); ?>>
198 <?php esc_html_e('Zoom', 'master-addons'); ?>
199 </option>
200 </select>
201 </td>
202 </tr>
203 <tr>
204 <th scope="row"><?php esc_html_e('Animation Duration', 'master-addons'); ?></th>
205 <td>
206 <input type="number" name="settings[appearance][animation_duration]"
207 value="<?php echo esc_attr($settings['animation_duration']); ?>" min="100" max="2000">
208 <span class="description"><?php esc_html_e('Duration in milliseconds', 'master-addons'); ?></span>
209 </td>
210 </tr>
211 <tr>
212 <th scope="row"><?php esc_html_e('Overlay Color', 'master-addons'); ?></th>
213 <td>
214 <input type="text" name="settings[appearance][overlay_color]"
215 value="<?php echo esc_attr($settings['overlay_color']); ?>"
216 class="ma-color-picker">
217 </td>
218 </tr>
219 <tr>
220 <th scope="row"><?php esc_html_e('Close Button Position', 'master-addons'); ?></th>
221 <td>
222 <select name="settings[appearance][close_button_position]">
223 <option value="top-right" <?php selected($settings['close_button_position'], 'top-right'); ?>>
224 <?php esc_html_e('Top Right', 'master-addons'); ?>
225 </option>
226 <option value="top-left" <?php selected($settings['close_button_position'], 'top-left'); ?>>
227 <?php esc_html_e('Top Left', 'master-addons'); ?>
228 </option>
229 <option value="bottom-right" <?php selected($settings['close_button_position'], 'bottom-right'); ?>>
230 <?php esc_html_e('Bottom Right', 'master-addons'); ?>
231 </option>
232 <option value="bottom-left" <?php selected($settings['close_button_position'], 'bottom-left'); ?>>
233 <?php esc_html_e('Bottom Left', 'master-addons'); ?>
234 </option>
235 </select>
236 </td>
237 </tr>
238 <tr>
239 <th scope="row"><?php esc_html_e('Z-Index', 'master-addons'); ?></th>
240 <td>
241 <input type="number" name="settings[appearance][z_index]"
242 value="<?php echo esc_attr($settings['z_index']); ?>" min="1">
243 <span class="description"><?php esc_html_e('Stack order of popups', 'master-addons'); ?></span>
244 </td>
245 </tr>
246 </table>
247 </div>
248 <?php
249 }
250
251 private function render_behavior_settings($settings) {
252 ?>
253 <div id="behavior" class="ma-tab-pane">
254 <h2><?php esc_html_e('Behavior Settings', 'master-addons'); ?></h2>
255
256 <table class="form-table">
257 <tr>
258 <th scope="row"><?php esc_html_e('Prevent Page Scroll', 'master-addons'); ?></th>
259 <td>
260 <label>
261 <input type="checkbox" name="settings[behavior][prevent_scroll]"
262 value="1" <?php checked($settings['prevent_scroll'], true); ?>>
263 <?php esc_html_e('Prevent page scrolling when popup is open', 'master-addons'); ?>
264 </label>
265 </td>
266 </tr>
267 <tr>
268 <th scope="row"><?php esc_html_e('Close on Overlay Click', 'master-addons'); ?></th>
269 <td>
270 <label>
271 <input type="checkbox" name="settings[behavior][close_on_overlay_click]"
272 value="1" <?php checked($settings['close_on_overlay_click'], true); ?>>
273 <?php esc_html_e('Close popup when overlay is clicked', 'master-addons'); ?>
274 </label>
275 </td>
276 </tr>
277 <tr>
278 <th scope="row"><?php esc_html_e('Close on ESC Key', 'master-addons'); ?></th>
279 <td>
280 <label>
281 <input type="checkbox" name="settings[behavior][close_on_esc_key]"
282 value="1" <?php checked($settings['close_on_esc_key'], true); ?>>
283 <?php esc_html_e('Close popup when ESC key is pressed', 'master-addons'); ?>
284 </label>
285 </td>
286 </tr>
287 <tr>
288 <th scope="row"><?php esc_html_e('Auto Focus', 'master-addons'); ?></th>
289 <td>
290 <label>
291 <input type="checkbox" name="settings[behavior][auto_focus]"
292 value="1" <?php checked($settings['auto_focus'], true); ?>>
293 <?php esc_html_e('Automatically focus first input field in popup', 'master-addons'); ?>
294 </label>
295 </td>
296 </tr>
297 <tr>
298 <th scope="row"><?php esc_html_e('Mobile Behavior', 'master-addons'); ?></th>
299 <td>
300 <select name="settings[behavior][mobile_behavior]">
301 <option value="responsive" <?php selected($settings['mobile_behavior'], 'responsive'); ?>>
302 <?php esc_html_e('Responsive', 'master-addons'); ?>
303 </option>
304 <option value="full-screen" <?php selected($settings['mobile_behavior'], 'full-screen'); ?>>
305 <?php esc_html_e('Full Screen', 'master-addons'); ?>
306 </option>
307 <option value="disable" <?php selected($settings['mobile_behavior'], 'disable'); ?>>
308 <?php esc_html_e('Disable on Mobile', 'master-addons'); ?>
309 </option>
310 </select>
311 </td>
312 </tr>
313 </table>
314 </div>
315 <?php
316 }
317
318 private function render_advanced_settings($settings) {
319 ?>
320 <div id="advanced" class="ma-tab-pane">
321 <h2><?php esc_html_e('Advanced Settings', 'master-addons'); ?></h2>
322
323 <table class="form-table">
324 <tr>
325 <th scope="row"><?php esc_html_e('Cookie Expiration', 'master-addons'); ?></th>
326 <td>
327 <input type="number" name="settings[advanced][cookie_expiration]"
328 value="<?php echo esc_attr($settings['cookie_expiration']); ?>" min="1">
329 <span class="description"><?php esc_html_e('Days until cookies expire', 'master-addons'); ?></span>
330 </td>
331 </tr>
332 <tr>
333 <th scope="row"><?php esc_html_e('Test Mode', 'master-addons'); ?></th>
334 <td>
335 <label>
336 <input type="checkbox" name="settings[advanced][test_mode]"
337 value="1" <?php checked($settings['test_mode'], true); ?>>
338 <?php esc_html_e('Enable test mode (only show popups to specified IPs)', 'master-addons'); ?>
339 </label>
340 </td>
341 </tr>
342 <tr>
343 <th scope="row"><?php esc_html_e('Test Mode IPs', 'master-addons'); ?></th>
344 <td>
345 <textarea name="settings[advanced][test_mode_ips]" rows="3" class="large-text"><?php
346 echo esc_textarea($settings['test_mode_ips']);
347 ?></textarea>
348 <p class="description"><?php esc_html_e('Enter IP addresses, one per line', 'master-addons'); ?></p>
349 </td>
350 </tr>
351 <tr>
352 <th scope="row"><?php esc_html_e('Custom CSS', 'master-addons'); ?></th>
353 <td>
354 <textarea name="settings[advanced][custom_css]" rows="5" class="large-text code"><?php
355 echo esc_textarea($settings['custom_css']);
356 ?></textarea>
357 <p class="description"><?php esc_html_e('Add custom CSS for all popups', 'master-addons'); ?></p>
358 </td>
359 </tr>
360 <tr>
361 <th scope="row"><?php esc_html_e('Custom JavaScript', 'master-addons'); ?></th>
362 <td>
363 <textarea name="settings[advanced][custom_js]" rows="5" class="large-text code"><?php
364 echo esc_textarea($settings['custom_js']);
365 ?></textarea>
366 <p class="description"><?php esc_html_e('Add custom JavaScript for all popups', 'master-addons'); ?></p>
367 </td>
368 </tr>
369 </table>
370 </div>
371 <?php
372 }
373
374 private function render_integrations_settings($settings) {
375 ?>
376 <div id="integrations" class="ma-tab-pane">
377 <h2><?php esc_html_e('Integration Settings', 'master-addons'); ?></h2>
378
379 <table class="form-table">
380 <tr>
381 <th scope="row"><?php esc_html_e('Google Analytics', 'master-addons'); ?></th>
382 <td>
383 <label>
384 <input type="checkbox" name="settings[integrations][google_analytics]"
385 value="1" <?php checked($settings['google_analytics'], true); ?>>
386 <?php esc_html_e('Track popup events in Google Analytics', 'master-addons'); ?>
387 </label>
388 </td>
389 </tr>
390 <tr>
391 <th scope="row"><?php esc_html_e('GA Event Name', 'master-addons'); ?></th>
392 <td>
393 <input type="text" name="settings[integrations][google_analytics_event]"
394 value="<?php echo esc_attr($settings['google_analytics_event']); ?>"
395 class="regular-text">
396 </td>
397 </tr>
398 <tr>
399 <th scope="row"><?php esc_html_e('Facebook Pixel', 'master-addons'); ?></th>
400 <td>
401 <label>
402 <input type="checkbox" name="settings[integrations][facebook_pixel]"
403 value="1" <?php checked($settings['facebook_pixel'], true); ?>>
404 <?php esc_html_e('Track popup events in Facebook Pixel', 'master-addons'); ?>
405 </label>
406 </td>
407 </tr>
408 <tr>
409 <th scope="row"><?php esc_html_e('FB Event Name', 'master-addons'); ?></th>
410 <td>
411 <input type="text" name="settings[integrations][facebook_pixel_event]"
412 value="<?php echo esc_attr($settings['facebook_pixel_event']); ?>"
413 class="regular-text">
414 </td>
415 </tr>
416 <tr>
417 <th scope="row"><?php esc_html_e('MailChimp API Key', 'master-addons'); ?></th>
418 <td>
419 <input type="text" name="settings[integrations][mailchimp_api]"
420 value="<?php echo esc_attr($settings['mailchimp_api']); ?>"
421 class="regular-text">
422 </td>
423 </tr>
424 <tr>
425 <th scope="row"><?php esc_html_e('MailChimp List ID', 'master-addons'); ?></th>
426 <td>
427 <input type="text" name="settings[integrations][mailchimp_list_id]"
428 value="<?php echo esc_attr($settings['mailchimp_list_id']); ?>"
429 class="regular-text">
430 </td>
431 </tr>
432 </table>
433 </div>
434 <?php
435 }
436
437 private function render_performance_settings($settings) {
438 ?>
439 <div id="performance" class="ma-tab-pane">
440 <h2><?php esc_html_e('Performance Settings', 'master-addons'); ?></h2>
441
442 <table class="form-table">
443 <tr>
444 <th scope="row"><?php esc_html_e('Lazy Load', 'master-addons'); ?></th>
445 <td>
446 <label>
447 <input type="checkbox" name="settings[performance][lazy_load]"
448 value="1" <?php checked($settings['lazy_load'], true); ?>>
449 <?php esc_html_e('Lazy load popup content', 'master-addons'); ?>
450 </label>
451 </td>
452 </tr>
453 <tr>
454 <th scope="row"><?php esc_html_e('Preload Fonts', 'master-addons'); ?></th>
455 <td>
456 <label>
457 <input type="checkbox" name="settings[performance][preload_fonts]"
458 value="1" <?php checked($settings['preload_fonts'], true); ?>>
459 <?php esc_html_e('Preload popup fonts for better performance', 'master-addons'); ?>
460 </label>
461 </td>
462 </tr>
463 <tr>
464 <th scope="row"><?php esc_html_e('Minify CSS', 'master-addons'); ?></th>
465 <td>
466 <label>
467 <input type="checkbox" name="settings[performance][minify_css]"
468 value="1" <?php checked($settings['minify_css'], true); ?>>
469 <?php esc_html_e('Minify popup CSS', 'master-addons'); ?>
470 </label>
471 </td>
472 </tr>
473 <tr>
474 <th scope="row"><?php esc_html_e('Minify JavaScript', 'master-addons'); ?></th>
475 <td>
476 <label>
477 <input type="checkbox" name="settings[performance][minify_js]"
478 value="1" <?php checked($settings['minify_js'], true); ?>>
479 <?php esc_html_e('Minify popup JavaScript', 'master-addons'); ?>
480 </label>
481 </td>
482 </tr>
483 <tr>
484 <th scope="row"><?php esc_html_e('Cache Duration', 'master-addons'); ?></th>
485 <td>
486 <input type="number" name="settings[performance][cache_duration]"
487 value="<?php echo esc_attr($settings['cache_duration']); ?>" min="60">
488 <span class="description"><?php esc_html_e('Cache duration in seconds', 'master-addons'); ?></span>
489 </td>
490 </tr>
491 </table>
492 </div>
493 <?php
494 }
495
496 private function process_settings_save() {
497 $settings = isset($_POST['settings']) ? map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' ) : []; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified in render_settings_page() before this method is called
498
499 // Sanitize settings
500 $sanitized_settings = $this->sanitize_settings($settings);
501
502 // Save settings
503 if ($this->save_settings($sanitized_settings)) {
504 add_action('admin_notices', function() {
505 ?>
506 <div class="notice notice-success is-dismissible">
507 <p><?php esc_html_e('Settings saved successfully!', 'master-addons'); ?></p>
508 </div>
509 <?php
510 });
511 } else {
512 add_action('admin_notices', function() {
513 ?>
514 <div class="notice notice-error is-dismissible">
515 <p><?php esc_html_e('Failed to save settings. Please try again.', 'master-addons'); ?></p>
516 </div>
517 <?php
518 });
519 }
520 }
521
522 private function sanitize_settings($settings) {
523 $sanitized = [];
524
525 foreach ($settings as $section => $values) {
526 foreach ($values as $key => $value) {
527 if (is_array($value)) {
528 $sanitized[$section][$key] = array_map('sanitize_text_field', $value);
529 } elseif (in_array($key, ['custom_css', 'custom_js', 'test_mode_ips'])) {
530 $sanitized[$section][$key] = sanitize_textarea_field($value);
531 } else {
532 $sanitized[$section][$key] = sanitize_text_field($value);
533 }
534 }
535 }
536
537 return $sanitized;
538 }
539 }