PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.9
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.9
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Extensions / PopupNotification / PopupNotification.php

PopupNotification.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.9, at includes/Extensions/PopupNotification/PopupNotification.php

1,059 lines 48.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Popup Notification
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Extensions\Popup;
10
11 use NotificationX\Admin\InfoTooltipManager;
12 use NotificationX\Core\PostType;
13 use NotificationX\GetInstance;
14 use NotificationX\Core\Rules;
15 use NotificationX\Extensions\GlobalFields;
16 use NotificationX\Extensions\Extension;
17
18 /**
19 * Popup Extension
20 * @method static Popup get_instance($args = null)
21 */
22 class PopupNotification extends Extension {
23 /**
24 * Instance of Popup
25 *
26 * @var Popup
27 */
28 use GetInstance;
29
30 public $priority = 15;
31 public $id = 'popup_notification';
32 public $doc_link = 'https://notificationx.com/docs/how-to-show-announcement-using-notificationx/';
33 public $types = 'popup';
34 public $module = 'modules_popup';
35
36 /**
37 * Initially Invoked when initialized.
38 */
39 public function __construct(){
40 parent::__construct();
41 }
42
43 public function init() {
44 parent::init();
45 }
46
47 public function init_extension()
48 {
49 $this->title = __('Announcement', 'notificationx');
50 $this->module_title = __('Announcement', 'notificationx');
51 $this->themes = [
52 'theme-one' => [
53 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-one.png',
54 'defaults' => [
55 'popup_title' => __('Want to build credibility & boost sales?', 'notificationx'),
56 'popup_content' => __('We help you optimize conversions & drive sales', 'notificationx'),
57 'popup_button_text' => __('Get Started with Free Plan', 'notificationx'),
58 'position' => 'center',
59 ],
60 'column' => "5",
61 ],
62 'theme-two' => [
63 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-two.png',
64 'defaults' => [
65 'popup_title' => __('Boost your sales using SureCart', 'notificationx'),
66 'popup_content' => __('<iframe width="560" height="315" src="https://www.youtube.com/embed/dw176Jmk74M?si=3suUqkCkQuYQrh2G" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>', 'notificationx'),
67 'popup_button_text' => __('See How', 'notificationx'),
68 'position' => 'center',
69 ],
70 'column' => "5",
71 ],
72
73 'theme-four' => [
74 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-four.webp',
75 'defaults' => [
76 'popup_title' => __('Need Help?', 'notificationx'),
77 'popup_content' => __('Get the latest news and updates delivered to your inbox.', 'notificationx'),
78 'popup_button_text' => __('Submit', 'notificationx'),
79 'position' => 'center',
80 ],
81 'column' => "5",
82 ],
83 'theme-five' => [
84 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-five.webp',
85 'defaults' => [
86 'popup_title' => __('Need Help?', 'notificationx'),
87 'popup_content' => __('Subscribe to receive exclusive offers and updates directly in your inbox.', 'notificationx'),
88 'popup_email_placeholder' => __('Enter your email address', 'notificationx'),
89 'popup_button_text' => __('Submit', 'notificationx'),
90 'position' => 'center',
91 ],
92 'is_pro' => true,
93 'column' => "5",
94 ],
95 'theme-seven' => [
96 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-seven.webp',
97 'defaults' => [
98 'popup_title' => __('Want latest updates?', 'notificationx'),
99 'popup_subtitle' => __('Would like to get the lastes news & updates instantly?', 'notificationx'),
100 'popup_email_placeholder' => __('Enter email address', 'notificationx'),
101 'popup_button_text' => __('Get In Touch', 'notificationx'),
102 'popup_icon' => 'mail_icon.svg',
103 'popup_button_icon' => 'mail_icon.svg',
104 'position' => 'center',
105 ],
106 'is_pro' => true,
107 'column' => "5",
108 ],
109 'theme-six' => [
110 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-six.webp',
111 'defaults' => [
112 'popup_title' => __('Get latest news & updates', 'notificationx'),
113 'popup_email_placeholder' => __('Your email address', 'notificationx'),
114 'popup_button_text' => __('Submit Now', 'notificationx'),
115 'position' => 'center',
116 ],
117 'is_pro' => true,
118 'column' => "5",
119 ],
120 'theme-three' => [
121 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/popup/popup-theme-three.png',
122 'defaults' => [
123 'popup_title' => __('All Offers', 'notificationx'),
124 'popup_button_text' => __('Latest Offers', 'notificationx'),
125 'popup_button_icon' => 'latest_offer.svg',
126 'position' => 'center',
127 ],
128 'column' => "5",
129 ],
130
131 ];
132 }
133
134 public function init_fields() {
135 parent::init_fields();
136 add_filter('nx_design_tab_fields', [$this, 'design_fields'], 99);
137 add_filter('nx_content_fields', [$this, 'content_fields'], 999);
138 add_filter('nx_customize_fields', [$this, 'customize_fields'], 999);
139 add_filter('nx_display_fields', [$this, 'display_fields'], 999);
140 }
141
142 public function display_fields($fields) {
143 // Hide image selection
144 if (isset($fields['image-section'])) {
145 $fields['image-section'] = Rules::is('source', $this->id, true, $fields['image-section']);
146 }
147 return $fields;
148 }
149
150 public function design_fields( $fields ) {
151 if (isset($fields['advance_design_section']['fields']['design'])) {
152 $fields['advance_design_section']['fields']['design'] = Rules::is('source', $this->id, true, $fields['advance_design_section']['fields']['design']);
153 }
154 if (isset($fields['advance_design_section']['fields']['typography'])) {
155 $fields['advance_design_section']['fields']['typography'] = Rules::is('source', $this->id, true, $fields['advance_design_section']['fields']['typography']);
156 }
157 if (isset($fields['advance_design_section']['fields']['image-appearance'])) {
158 $fields['advance_design_section']['fields']['image-appearance'] = Rules::is('source', $this->id, true, $fields['advance_design_section']['fields']['image-appearance']);
159 }
160 if (isset($fields['advance_design_section']['fields']['link_button_design'])) {
161 $fields['advance_design_section']['fields']['link_button_design'] = Rules::is('source', $this->id, true, $fields['advance_design_section']['fields']['link_button_design']);
162 }
163
164 // Popup Container Design Section
165 $fields['advance_design_section']['fields']['popup_design'] = [
166 'label' => __("Popup Design", 'notificationx'),
167 'name' => "popup_design",
168 'type' => "section",
169 'priority' => 5,
170 'rules' => Rules::logicalRule([
171 Rules::is('source', $this->id, false),
172 Rules::is('advance_edit', true),
173 ]),
174 'fields' => [
175 [
176 'label' => __("Background Color", 'notificationx'),
177 'name' => "popup_bg_color",
178 'type' => "colorpicker",
179 ],
180 [
181 'label' => __("Overlay Background Color", 'notificationx'),
182 'name' => "overlay_color",
183 'type' => "colorpicker",
184 'help' => __('Background color of the overlay behind the popup', 'notificationx'),
185 ],
186 [
187 'label' => __('Popup Width', 'notificationx'),
188 'name' => "popup_width",
189 'type' => "number",
190 'description' => 'px',
191 'help' => __('Maximum width of the popup container', 'notificationx'),
192 ],
193 [
194 'label' => __('Border Radius', 'notificationx'),
195 'name' => "popup_border_radius",
196 'type' => "number",
197 'description' => 'px',
198 'help' => __('Rounded corners for the popup container', 'notificationx'),
199 ],
200 [
201 'label' => __('Popup Padding', 'notificationx'),
202 'name' => "popup_padding",
203 'type' => "text",
204 'help' => __('Internal spacing of popup content (e.g., 30px or 20px 30px)', 'notificationx'),
205 ],
206 [
207 'label' => __("Close Button Color", 'notificationx'),
208 'name' => "close_btn_color",
209 'type' => "colorpicker",
210 ],
211 [
212 'label' => __('Close Button Size', 'notificationx'),
213 'name' => "close_btn_size",
214 'type' => "number",
215 'description' => 'px',
216 ],
217 ]
218 ];
219
220 // Typography Section
221 $fields['advance_design_section']['fields']['popup_typography'] = [
222 'label' => __("Typography", 'notificationx'),
223 'name' => "popup_typography",
224 'type' => "section",
225 'priority' => 6,
226 'rules' => Rules::logicalRule([
227 Rules::is('source', $this->id, false),
228 Rules::is('advance_edit', true),
229 ]),
230 'fields' => [
231 [
232 'label' => __("Title Color", 'notificationx'),
233 'name' => "popup_title_color",
234 'type' => "colorpicker",
235 ],
236 [
237 'label' => __('Title Font Size', 'notificationx'),
238 'name' => "popup_title_font_size",
239 'type' => "number",
240 'description' => 'px',
241 'help' => __('Font size for the popup title', 'notificationx'),
242 ],
243 [
244 'label' => __('Title Font Weight', 'notificationx'),
245 'name' => "popup_title_font_weight",
246 'type' => "select",
247 'options' => GlobalFields::get_instance()->normalize_fields([
248 '300' => __('Light (300)', 'notificationx'),
249 '400' => __('Normal (400)', 'notificationx'),
250 '500' => __('Medium (500)', 'notificationx'),
251 '600' => __('Semi Bold (600)', 'notificationx'),
252 '700' => __('Bold (700)', 'notificationx'),
253 '800' => __('Extra Bold (800)', 'notificationx'),
254 ]),
255 ],
256 [
257 'label' => __("Subtitle Color", 'notificationx'),
258 'name' => "popup_subtitle_color",
259 'type' => "colorpicker",
260 'rules' => Rules::is('themes', 'popup_notification_theme-seven'),
261 ],
262 [
263 'label' => __('Subtitle Font Size', 'notificationx'),
264 'name' => "popup_subtitle_font_size",
265 'type' => "number",
266 'description' => 'px',
267 'help' => __('Font size for the popup subtitle', 'notificationx'),
268 'rules' => Rules::is('themes', 'popup_notification_theme-seven'),
269 ],
270 [
271 'label' => __("Content/Message Color", 'notificationx'),
272 'name' => "popup_content_color",
273 'type' => "colorpicker",
274 'rules' => Rules::logicalRule([
275 Rules::is('themes', 'popup_notification_theme-one'),
276 Rules::is('themes', 'popup_notification_theme-two'),
277 Rules::is('themes', 'popup_notification_theme-three'),
278 Rules::is('themes', 'popup_notification_theme-four'),
279 Rules::is('themes', 'popup_notification_theme-five'),
280 ], 'or'),
281 ],
282 [
283 'label' => __('Content/Message Font Size', 'notificationx'),
284 'name' => "popup_content_font_size",
285 'type' => "number",
286 'description' => 'px',
287 'help' => __('Font size for the popup content/message text', 'notificationx'),
288 'rules' => Rules::logicalRule([
289 Rules::is('themes', 'popup_notification_theme-one'),
290 Rules::is('themes', 'popup_notification_theme-two'),
291 Rules::is('themes', 'popup_notification_theme-three'),
292 Rules::is('themes', 'popup_notification_theme-four'),
293 Rules::is('themes', 'popup_notification_theme-five'),
294 ], 'or'),
295 ],
296 ]
297 ];
298
299 // Button Design Section
300 $fields['advance_design_section']['fields']['popup_button_design'] = [
301 'label' => __("Button Design", 'notificationx'),
302 'name' => "popup_button_design",
303 'type' => "section",
304 'priority' => 7,
305 'rules' => Rules::logicalRule([
306 Rules::is('source', $this->id, false),
307 Rules::is('advance_edit', true),
308 ]),
309 'fields' => [
310 [
311 'label' => __("Background Color", 'notificationx'),
312 'name' => "popup_button_bg_color",
313 'type' => "colorpicker",
314 ],
315 [
316 'label' => __("Hover Background Color", 'notificationx'),
317 'name' => "popup_button_hover_bg_color",
318 'type' => "colorpicker",
319 'help' => __('Background color when button is hovered', 'notificationx'),
320 ],
321 [
322 'label' => __("Text Color", 'notificationx'),
323 'name' => "popup_button_text_color",
324 'type' => "colorpicker",
325 ],
326 [
327 'label' => __("Hover Text Color", 'notificationx'),
328 'name' => "popup_button_hover_text_color",
329 'type' => "colorpicker",
330 'help' => __('Text color when button is hovered', 'notificationx'),
331 ],
332 [
333 'label' => __("Border Color", 'notificationx'),
334 'name' => "popup_button_border_color",
335 'type' => "colorpicker",
336 ],
337 [
338 'label' => __("Hover Border Color", 'notificationx'),
339 'name' => "popup_button_border_hover_color",
340 'type' => "colorpicker",
341 ],
342 [
343 'label' => __('Border Width', 'notificationx'),
344 'name' => "popup_button_border_width",
345 'type' => "number",
346 'description' => 'px',
347 'help' => __('Width of the button border', 'notificationx'),
348 ],
349 [
350 'label' => __('Font Size', 'notificationx'),
351 'name' => "popup_button_font_size",
352 'type' => "number",
353 'description' => 'px',
354 ],
355 [
356 'label' => __('Font Weight', 'notificationx'),
357 'name' => "popup_button_font_weight",
358 'type' => "select",
359 'options' => GlobalFields::get_instance()->normalize_fields([
360 '300' => __('Light (300)', 'notificationx'),
361 '400' => __('Normal (400)', 'notificationx'),
362 '500' => __('Medium (500)', 'notificationx'),
363 '600' => __('Semi Bold (600)', 'notificationx'),
364 '700' => __('Bold (700)', 'notificationx'),
365 ]),
366 ],
367 [
368 'label' => __('Border Radius', 'notificationx'),
369 'name' => "popup_button_border_radius",
370 'type' => "number",
371 'description' => 'px',
372 'help' => __('Rounded corners for the button', 'notificationx'),
373 ],
374 [
375 'label' => __('Padding', 'notificationx'),
376 'name' => "popup_button_padding",
377 'type' => "text",
378 'help' => __('Button spacing in CSS format (e.g., 12px 24px)', 'notificationx'),
379 ],
380 [
381 'label' => __('Button Width', 'notificationx'),
382 'name' => "popup_button_width",
383 'type' => "select",
384 'default' => 'auto',
385 'options' => GlobalFields::get_instance()->normalize_fields([
386 'auto' => __('Auto Width', 'notificationx'),
387 '100%' => __('Full Width', 'notificationx'),
388 'custom' => __('Custom Width', 'notificationx'),
389 ]),
390 ],
391 [
392 'label' => __('Custom Button Width', 'notificationx'),
393 'name' => "popup_button_custom_width",
394 'type' => "number",
395 'description' => 'px',
396 'rules' => Rules::is('popup_button_width', 'custom'),
397 ],
398 ]
399 ];
400
401 // Email Input Design Section (for email collection themes)
402 $fields['advance_design_section']['fields']['popup_email_design'] = [
403 'label' => __("Email Input Design", 'notificationx'),
404 'name' => "popup_email_design",
405 'type' => "section",
406 'priority' => 8,
407 'rules' => Rules::logicalRule([
408 Rules::is('source', $this->id, false),
409 Rules::is('advance_edit', true),
410 Rules::logicalRule([
411 Rules::is('themes', 'popup_notification_theme-five'),
412 Rules::is('themes', 'popup_notification_theme-six'),
413 Rules::is('themes', 'popup_notification_theme-seven'),
414 ], 'or'),
415 ]),
416 'fields' => [
417 [
418 'label' => __("Input Background Color", 'notificationx'),
419 'name' => "popup_email_bg_color",
420 'type' => "colorpicker",
421 ],
422 [
423 'label' => __("Input Text Color", 'notificationx'),
424 'name' => "popup_email_text_color",
425 'type' => "colorpicker",
426 ],
427 [
428 'label' => __("Input Border Color", 'notificationx'),
429 'name' => "popup_email_border_color",
430 'type' => "colorpicker",
431 ],
432 [
433 'label' => __("Input Focus Border Color", 'notificationx'),
434 'name' => "popup_email_focus_border_color",
435 'type' => "colorpicker",
436 'help' => __('Border color when input is focused', 'notificationx'),
437 ],
438 [
439 'label' => __("Placeholder Text Color", 'notificationx'),
440 'name' => "popup_email_placeholder_color",
441 'type' => "colorpicker",
442 ],
443 [
444 'label' => __('Input Font Size', 'notificationx'),
445 'name' => "popup_email_font_size",
446 'type' => "number",
447 'description' => 'px',
448 ],
449 [
450 'label' => __('Input Border Width', 'notificationx'),
451 'name' => "popup_email_border_width",
452 'type' => "number",
453 'description' => 'px',
454 ],
455 [
456 'label' => __('Input Border Radius', 'notificationx'),
457 'name' => "popup_email_border_radius",
458 'type' => "number",
459 'description' => 'px',
460 ],
461 [
462 'label' => __('Input Padding', 'notificationx'),
463 'name' => "popup_email_padding",
464 'type' => "text",
465 'help' => __('Input field spacing in CSS format (e.g., 12px 16px)', 'notificationx'),
466 ],
467 [
468 'label' => __('Input Height', 'notificationx'),
469 'name' => "popup_email_height",
470 'type' => "number",
471 'description' => 'px',
472 'help' => __('Height of the email input field', 'notificationx'),
473 ],
474 ]
475 ];
476
477 // Repeater Items Design Section (for theme-three only)
478 $fields['advance_design_section']['fields']['popup_repeater_design'] = [
479 'label' => __("Content Items Design", 'notificationx'),
480 'name' => "popup_repeater_design",
481 'type' => "section",
482 'priority' => 9,
483 'rules' => Rules::logicalRule([
484 Rules::is('source', $this->id, false),
485 Rules::is('advance_edit', true),
486 Rules::is('themes', 'popup_notification_theme-three'),
487 ]),
488 'fields' => [
489 [
490 'label' => __("Item Background Color", 'notificationx'),
491 'name' => "popup_repeater_item_bg_color",
492 'type' => "colorpicker",
493 'help' => __('Background color for each content item', 'notificationx'),
494 ],
495 [
496 'label' => __("Highlight Text Color", 'notificationx'),
497 'name' => "popup_repeater_highlight_color",
498 'type' => "colorpicker",
499 'help' => __('Color for the highlight text (e.g., "30% OFF")', 'notificationx'),
500 ],
501 [
502 'label' => __("Item Title Color", 'notificationx'),
503 'name' => "popup_repeater_title_color",
504 'type' => "colorpicker",
505 ],
506 [
507 'label' => __('Item Title Font Size', 'notificationx'),
508 'name' => "popup_repeater_title_font_size",
509 'type' => "number",
510 'description' => 'px',
511 ],
512 [
513 'label' => __('Item Title Font Weight', 'notificationx'),
514 'name' => "popup_repeater_title_font_weight",
515 'type' => "select",
516 'options' => GlobalFields::get_instance()->normalize_fields([
517 '400' => __('Normal (400)', 'notificationx'),
518 '500' => __('Medium (500)', 'notificationx'),
519 '600' => __('Semi Bold (600)', 'notificationx'),
520 '700' => __('Bold (700)', 'notificationx'),
521 ]),
522 ],
523 [
524 'label' => __("Item Subtitle Color", 'notificationx'),
525 'name' => "popup_repeater_subtitle_color",
526 'type' => "colorpicker",
527 ],
528 [
529 'label' => __('Item Subtitle Font Size', 'notificationx'),
530 'name' => "popup_repeater_subtitle_font_size",
531 'type' => "number",
532 'description' => 'px',
533 ],
534 [
535 'label' => __('Item Border Radius', 'notificationx'),
536 'name' => "popup_repeater_item_border_radius",
537 'type' => "number",
538 'description' => 'px',
539 'help' => __('Rounded corners for each content item', 'notificationx'),
540 ],
541 [
542 'label' => __('Item Padding', 'notificationx'),
543 'name' => "popup_repeater_item_padding",
544 'type' => "text",
545 'help' => __('Internal spacing for each content item (e.g., 16px)', 'notificationx'),
546 ],
547 [
548 'label' => __('Item Spacing', 'notificationx'),
549 'name' => "popup_repeater_item_spacing",
550 'type' => "number",
551 'description' => 'px',
552 'help' => __('Space between content items', 'notificationx'),
553 ],
554 ]
555 ];
556
557 return $fields;
558 }
559
560 public function content_fields( $fields ) {
561 if (isset($fields['utm_options'])) {
562 $fields['utm_options'] = Rules::is('source', $this->id, true, $fields['utm_options']);
563 }
564 if (isset($fields['content'])) {
565 $fields['content'] = Rules::is('source', $this->id, true, $fields['content']);
566 }
567
568 $fields['popup_content'] = [
569 'label' => __('Popup Content', 'notificationx'),
570 'name' => 'popup_content',
571 'type' => 'section',
572 'priority' => 5,
573 'rules' => Rules::is('source', $this->id),
574 'fields' => [
575 [
576 'label' => __('Title', 'notificationx'),
577 'name' => 'popup_title',
578 'type' => 'text',
579 'priority' => 10,
580 'default' => __('Special Offer!', 'notificationx'),
581 ],
582 [
583 'label' => __('Subtitle', 'notificationx'),
584 'name' => 'popup_subtitle',
585 'type' => 'text',
586 'priority' => 12,
587 'default' => __('Would like to get the latest news & updates instantly?', 'notificationx'),
588 'rules' => Rules::is('themes', 'popup_notification_theme-seven'),
589 ],
590 [
591 'label' => __('Popup Icon', 'notificationx'),
592 'name' => 'popup_icon',
593 'type' => 'icon-picker',
594 'priority' => 15,
595 'iconPrefix' => NOTIFICATIONX_ADMIN_URL . 'images/icons/',
596 'default' => 'mail_icon.svg',
597 'rules' => Rules::is('themes', 'popup_notification_theme-seven'),
598 'options' => [
599 [
600 'icon' => 'mail_icon.svg',
601 'label' => __('Mail Icon', 'notificationx')
602 ],
603 ],
604 ],
605 [
606 'label' => __('Content', 'notificationx'),
607 'name' => 'popup_content',
608 'type' => 'textarea',
609 'priority' => 20,
610 'default' => __('Don\'t miss out on this amazing deal!', 'notificationx'),
611 'rules' => Rules::logicalRule([
612 Rules::is('themes', 'popup_notification_theme-one'),
613 Rules::is('themes', 'popup_notification_theme-two'),
614 Rules::is('themes', 'popup_notification_theme-seven'),
615 ], 'or'),
616 ],
617 // Form Field Toggles - only for form submission themes (4-7)
618 [
619 'label' => __('Show Name Field', 'notificationx'),
620 'name' => 'popup_show_name_field',
621 'type' => 'toggle',
622 'priority' => 25,
623 'default' => false,
624 'rules' => Rules::logicalRule([
625 Rules::is('themes', 'popup_notification_theme-four'),
626 Rules::is('themes', 'popup_notification_theme-five'),
627 Rules::is('themes', 'popup_notification_theme-six'),
628 Rules::is('themes', 'popup_notification_theme-seven'),
629 ], 'or'),
630 'is_pro' => true,
631 ],
632 [
633 'label' => __('Name Field Text', 'notificationx'),
634 'name' => 'popup_name_placeholder',
635 'type' => 'text',
636 'priority' => 30,
637 'default' => __('Enter your name', 'notificationx'),
638 'rules' => Rules::logicalRule([
639 Rules::logicalRule([
640 Rules::is('themes', 'popup_notification_theme-four'),
641 Rules::is('themes', 'popup_notification_theme-five'),
642 Rules::is('themes', 'popup_notification_theme-six'),
643 Rules::is('themes', 'popup_notification_theme-seven'),
644 ], 'or'),
645 Rules::is('popup_show_name_field', true),
646 ]),
647 ],
648 [
649 'label' => __('Show Email Field', 'notificationx'),
650 'name' => 'popup_show_email_field',
651 'type' => 'toggle',
652 'priority' => 35,
653 'info' => InfoTooltipManager::get_instance()->render('popup_notification_email_field'),
654 'rules' => Rules::logicalRule([
655 Rules::is('themes', 'popup_notification_theme-four'),
656 Rules::is('themes', 'popup_notification_theme-five'),
657 Rules::is('themes', 'popup_notification_theme-six'),
658 Rules::is('themes', 'popup_notification_theme-seven'),
659 ], 'or'),
660 'is_pro' => true,
661 ],
662 [
663 'label' => __('Email Field Text', 'notificationx'),
664 'name' => 'popup_email_placeholder',
665 'type' => 'text',
666 'priority' => 40,
667 'default' => __('Enter your email', 'notificationx'),
668 'rules' => Rules::logicalRule([
669 Rules::logicalRule([
670 Rules::is('themes', 'popup_notification_theme-four'),
671 Rules::is('themes', 'popup_notification_theme-five'),
672 Rules::is('themes', 'popup_notification_theme-six'),
673 Rules::is('themes', 'popup_notification_theme-seven'),
674 ], 'or'),
675 Rules::is('popup_show_email_field', true),
676 ]),
677 ],
678 [
679 'label' => __('Show Message Field', 'notificationx'),
680 'name' => 'popup_show_message_field',
681 'type' => 'toggle',
682 'priority' => 45,
683 'info' => InfoTooltipManager::get_instance()->render('popup_notification_message_field'),
684 'rules' => Rules::logicalRule([
685 Rules::is('themes', 'popup_notification_theme-four'),
686 Rules::is('themes', 'popup_notification_theme-five'),
687 Rules::is('themes', 'popup_notification_theme-six'),
688 Rules::is('themes', 'popup_notification_theme-seven'),
689 ], 'or'),
690 'default' => true,
691 ],
692 [
693 'label' => __('Message Field Text', 'notificationx'),
694 'name' => 'popup_message_placeholder',
695 'type' => 'text',
696 'priority' => 50,
697 'default' => __('Enter your message...', 'notificationx'),
698 'rules' => Rules::logicalRule([
699 Rules::logicalRule([
700 Rules::is('themes', 'popup_notification_theme-four'),
701 Rules::is('themes', 'popup_notification_theme-five'),
702 Rules::is('themes', 'popup_notification_theme-six'),
703 Rules::is('themes', 'popup_notification_theme-seven'),
704 ], 'or'),
705 Rules::is('popup_show_message_field', true),
706 ]),
707 ],
708
709 // Common Button Text field for all themes
710 [
711 'label' => __('Button Text', 'notificationx'),
712 'name' => 'popup_button_text',
713 'type' => 'text',
714 'priority' => 55,
715 'default' => __('Get Offer', 'notificationx'),
716 ],
717 // Button URL field - only for themes 1-3 (promotional themes with external links)
718 [
719 'label' => __('Button URL', 'notificationx'),
720 'name' => 'popup_button_url',
721 'type' => 'text',
722 'priority' => 60,
723 'default' => '#',
724 'rules' => Rules::logicalRule([
725 Rules::is('themes', 'popup_notification_theme-one'),
726 Rules::is('themes', 'popup_notification_theme-two'),
727 Rules::is('themes', 'popup_notification_theme-three'),
728 ], 'or'),
729 ],
730
731 // Button Icon field - only for theme-three and theme-seven
732 [
733 'label' => __('Button Icon', 'notificationx'),
734 'name' => 'popup_button_icon',
735 'type' => 'icon-picker',
736 'priority' => 62,
737 'iconPrefix' => NOTIFICATIONX_ADMIN_URL . 'images/icons/',
738 'default' => 'mail_icon.svg',
739 'options' => [
740 [
741 'icon' => 'mail_icon.svg',
742 'label' => __('Mail Icon', 'notificationx')
743 ],
744 [
745 'icon' => 'latest_offer.svg',
746 'label' => __('Latest OFfer', 'notificationx')
747 ],
748 [
749 'icon' => 'shop_now.svg',
750 'label' => __('Shop Now', 'notificationx')
751 ],
752 [
753 'icon' => 'shop_now_white.svg',
754 'label' => __('Shop Now White', 'notificationx')
755 ],
756 ],
757 'description' => __('Select an icon to display with the button text', 'notificationx'),
758 'rules' => Rules::logicalRule([
759 Rules::is('themes', 'popup_notification_theme-three'),
760 Rules::is('themes', 'popup_notification_theme-seven'),
761 ], 'or'),
762 ],
763 'open_in_new_tab' => [
764 'label' => __('Open URL in New Tab', 'notificationx'),
765 'name' => 'open_in_new_tab',
766 'type' => 'toggle',
767 'default' => false,
768 'rules' => Rules::logicalRule([
769 Rules::is('themes', 'popup_notification_theme-one'),
770 Rules::is('themes', 'popup_notification_theme-two'),
771 Rules::is('themes', 'popup_notification_theme-three'),
772 ], 'or'),
773 ],
774 // Repeater fields - only for theme-three
775 [
776 'label' => __('Content Items', 'notificationx'),
777 'name' => 'popup_content_repeater',
778 'type' => 'repeater',
779 'priority' => 65,
780 'rules' => Rules::is('themes', 'popup_notification_theme-three'),
781 'button' => [
782 'label' => __('Add New', 'notificationx')
783 ],
784 'fields' => [
785 [
786 'label' => __('Highlight Text', 'notificationx'),
787 'name' => 'repeater_highlight_text',
788 'type' => 'text',
789 'default' => __('30% OFF', 'notificationx'),
790 'help' => __('Text that will be highlighted in a different color (e.g., "30% OFF")', 'notificationx'),
791 ],
792 [
793 'label' => __('Title', 'notificationx'),
794 'name' => 'repeater_title',
795 'type' => 'text',
796 'default' => __('Feature Title', 'notificationx'),
797 ],
798 [
799 'label' => __('Subtitle', 'notificationx'),
800 'name' => 'repeater_subtitle',
801 'type' => 'text',
802 'default' => __('Feature description', 'notificationx'),
803 ],
804 ],
805 'default' => [
806 [
807 'repeater_highlight_text' => __('30% OFF', 'notificationx'),
808 'repeater_title' => __('Boost Sales', 'notificationx'),
809 'repeater_subtitle' => __('Increase conversions with social proof', 'notificationx'),
810 ],
811 [
812 'repeater_highlight_text' => __('50% OFF', 'notificationx'),
813 'repeater_title' => __('Build Trust', 'notificationx'),
814 'repeater_subtitle' => __('Show real customer activity', 'notificationx'),
815 ],
816 [
817 'repeater_highlight_text' => __('LIMITED', 'notificationx'),
818 'repeater_title' => __('Drive Action', 'notificationx'),
819 'repeater_subtitle' => __('Create urgency and FOMO', 'notificationx'),
820 ],
821 ],
822 ],
823 ]
824 ];
825
826 return $fields;
827 }
828
829 /**
830 * Generate entry key
831 *
832 * @param string $key
833 * @return string
834 */
835 public function key($key = '') {
836 return $this->id . '_' . $key;
837 }
838
839
840 /**
841 * Handle popup form submission
842 *
843 * @param WP_REST_Request $request
844 * @return WP_REST_Response
845 */
846 public function handle_popup_submission($request) {
847 $params = $request->get_params();
848
849 $id = $params['nx_id'];
850 $notificationx = PostType::get_instance()->get_post( $id );
851 if( !$notificationx ) {
852 return new \WP_REST_Response([
853 'success' => false,
854 'message' => __('Notification not found', 'notificationx'),
855 ], 404);
856 }
857
858 // Prepare entry data
859 $data = [
860 'title' => $params['title'] ?: __('Popup Submission', 'notificationx'),
861 'timestamp' => time(),
862 ];
863
864 // Add email if provided
865 if (!empty($params['email'])) {
866 $data['email'] = $params['email'];
867 }
868
869 // Add message if provided
870 if (!empty($params['message'])) {
871 $data['message'] = $params['message'];
872 }
873
874 if (!empty($params['name'])) {
875 $data['name'] = $params['name'];
876 }
877
878 // Add theme information
879 if (!empty($params['theme'])) {
880 $data['theme'] = $params['theme'];
881 }
882
883 // Add IP address
884 $data['ip'] = $this->get_user_ip();
885
886 // Use the post's own source so exit-intent submissions aren't mis-tagged as
887 // popup_notification (the same /popup-submit endpoint serves both types).
888 $source = ! empty( $notificationx['source'] ) ? $notificationx['source'] : $this->id;
889 $entry_key = $source . '_' . $params['nx_id'];
890 $entry = [
891 'nx_id' => $params['nx_id'],
892 'source' => $source,
893 'entry_key' => $entry_key,
894 'data' => $data,
895 ];
896
897 // Save the entry
898 $this->update_notification($entry);
899
900 return new \WP_REST_Response([
901 'success' => true,
902 'message' => __('Submission saved successfully', 'notificationx'),
903 ], 200);
904 }
905
906
907 /**
908 * Get user IP address
909 *
910 * @return string
911 */
912 private function get_user_ip() {
913 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
914 return $_SERVER['HTTP_CLIENT_IP'];
915 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
916 return $_SERVER['HTTP_X_FORWARDED_FOR'];
917 } else {
918 return $_SERVER['REMOTE_ADDR'] ?? '';
919 }
920 }
921
922
923 /**
924 * This method is an implementable method for All Extension coming forward.
925 *
926 * @param array $args Settings arguments.
927 * @return mixed
928 */
929 public function customize_fields($fields) {
930 $fields["timing"]['fields']['delay_between'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['delay_between']);
931 $fields["timing"]['fields']['display_for'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['display_for']);
932
933 if (isset($fields['behaviour'])) {
934 $fields['behaviour'] = Rules::is('source', $this->id, true, $fields['behaviour']);
935 }
936 if (isset($fields['sound_section'])) {
937 $fields['sound_section'] = Rules::is('source', $this->id, true, $fields['sound_section']);
938 }
939 if (isset($fields['queue_management'])) {
940 $fields['queue_management'] = Rules::is('source', $this->id, true, $fields['queue_management']);
941 }
942
943 $_fields = &$fields["appearance"]['fields'];
944 $conversion_position = &$_fields['position']['options'];
945
946 $conversion_position['center'] = [
947 'label' => __('Center', 'notificationx'),
948 'value' => 'center',
949 'rules' => Rules::is('source', $this->id),
950 ];
951 // Exit Intent Popup conversion (Announcement type).
952 $fields['exit_intent_settings'] = [
953 'label' => __('Exit Intent Popup', 'notificationx'),
954 'name' => 'exit_intent_settings',
955 'type' => 'section',
956 'priority' => 14,
957 'rules' => Rules::_is('source', $this->id),
958 'fields' => [
959 'convert_to_exit_intent' => [
960 'label' => __('Convert to Exit Intent Popup', 'notificationx'),
961 'name' => 'convert_to_exit_intent',
962 'type' => 'checkbox',
963 'default' => false,
964 'priority' => 5,
965 'description' => __('Show this Announcement as a centered popup when the visitor is about to leave the page.', 'notificationx'),
966 ],
967 'exit_intent_cookie_duration' => [
968 'label' => __('Cookie Duration', 'notificationx'),
969 'name' => 'exit_intent_cookie_duration',
970 'type' => 'number',
971 'default' => 7,
972 'min' => 1,
973 'max' => 365,
974 'priority' => 10,
975 'description' => __('Days', 'notificationx'),
976 'help' => __('Suppress the popup for this many days after it has been shown to a visitor.', 'notificationx'),
977 'rules' => Rules::_is('convert_to_exit_intent', true),
978 ],
979 ],
980 ];
981
982 $hide_when_exit_intent = Rules::logicalRule([
983 Rules::_is('source', $this->id, true),
984 Rules::_is('convert_to_exit_intent', true, true),
985 ], 'or');
986
987 if (isset($fields['timing']['fields']['display_for'])) {
988 $fields['timing']['fields']['display_for'] = Rules::add(
989 $hide_when_exit_intent,
990 $fields['timing']['fields']['display_for']
991 );
992 }
993 if (isset($fields['timing']['fields']['delay_between'])) {
994 $fields['timing']['fields']['delay_between'] = Rules::add(
995 $hide_when_exit_intent,
996 $fields['timing']['fields']['delay_between']
997 );
998 }
999 if (isset($_fields['position'])) {
1000 $_fields['position'] = Rules::add(
1001 $hide_when_exit_intent,
1002 $_fields['position']
1003 );
1004 }
1005
1006 // Popup specific settings
1007 $fields['popup_settings'] = [
1008 'label' => __('Popup Settings', 'notificationx'),
1009 'name' => 'popup_settings',
1010 'type' => 'section',
1011 'priority' => 15,
1012 'rules' => Rules::is('source', $this->id),
1013 'fields' => [
1014 'show_close_button' => [
1015 'label' => __('Show Close Button', 'notificationx'),
1016 'name' => 'show_close_button',
1017 'type' => 'toggle',
1018 'default' => true,
1019 ],
1020 'close_on_button_click' => [
1021 'label' => __('Close on Button Click', 'notificationx'),
1022 'name' => 'close_on_button_click',
1023 'type' => 'toggle',
1024 'default' => true,
1025 ],
1026 'close_button_position' => [
1027 'label' => __('Close Button Position', 'notificationx'),
1028 'name' => 'close_button_position',
1029 'type' => 'select',
1030 'default' => 'top-right',
1031 'options' => GlobalFields::get_instance()->normalize_fields([
1032 'top-right' => __('Top Right', 'notificationx'),
1033 'top-left' => __('Top Left', 'notificationx'),
1034 'bottom-right' => __('Bottom Right', 'notificationx'),
1035 'bottom-left' => __('Bottom Left', 'notificationx'),
1036 ]),
1037 'rules' => Rules::is('show_close_button', true),
1038 ],
1039 ]
1040 ];
1041
1042 return $fields;
1043 }
1044
1045 public function doc(){
1046 return sprintf(__('<p>Create compelling Announcements that capture visitor interest and help you generate more leads on your WordPress site. Need help? Check out our <a href="%1$s" target="_blank">step-by-step guides</a> to build impactful Announcements.</p>
1047 <p>🎦 Watch the quick video <a target="_blank" href="%2$s">tutorial</a> for an easy walk-through.</p>
1048 <p><strong>Recommended Blogs:</strong></p>
1049 <p>🔥 <a target="_blank" href="%3$s">How to Create High-Performing Announcements with NotificationX?</a></p>
1050 <p><strong>Pro Tips:</strong></p>
1051 <p>✨ Use attention-grabbing headlines and clear action prompts to encourage more sign-ups.</p>', 'notificationx'),
1052 'https://notificationx.com/docs/how-to-show-announcement-using-notificationx/',
1053 'https://www.youtube.com/playlist?list=PLWHp1xKHCfxAj4AAs3kmzmDZKvjv6eycK',
1054 'https://notificationx.com/blog/announcement-notifications-on-wordpress'
1055 );
1056 }
1057
1058 }
1059