PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.12
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.12
3.3.3 3.3.2 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 All 158 releases
notificationx / includes / Extensions / PressBar / PressBar.php

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

2,289 lines 100.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * PressBar Extension
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Extensions\PressBar;
10
11 use NotificationX\Core\Analytics;
12 use NotificationX\Core\GetData;
13 use NotificationX\Core\Helper;
14 use NotificationX\Core\PostType;
15 use NotificationX\Core\Rules;
16 use NotificationX\Extensions\Extension;
17 use NotificationX\Extensions\GlobalFields;
18 use NotificationX\FrontEnd\Preview;
19 use NotificationX\GetInstance;
20
21 use Elementor\Core\Files\CSS\Post as Post_CSS;
22 use NotificationX\Admin\InfoTooltipManager;
23 use NotificationX\NotificationX;
24
25 /**
26 * PressBar Extension
27 * @method static PressBar get_instance($args = null)
28 */
29 class PressBar extends Extension {
30 /**
31 * Instance of Admin
32 *
33 * @var Admin
34 */
35 use GetInstance;
36
37 public $priority = 5;
38 public $id = 'press_bar';
39 public $doc_link = 'https://notificationx.com/docs/notification-bar/';
40 public $types = 'notification_bar';
41 public $module = 'modules_bar';
42 public $module_priority = 1;
43 public $default_theme = 'press_bar_theme-two';
44 public $bar_themes;
45 public $block_themes;
46 public $popup = array();
47
48 /**
49 * Initially Invoked when initialized.
50 */
51 public function __construct() {
52 parent::__construct();
53 add_action('init', [$this, 'register_post_type']);
54 add_action('init', [$this, 'load_plugin_dependencies'], -1);
55 add_filter( 'get_edit_post_link', function($link, $id){
56 $post = get_post( $id );
57 if ( $post && 'nx_bar' === $post->post_type && class_exists('\Elementor\Plugin') ) {
58 return \Elementor\Plugin::$instance->documents->get($id)->get_edit_url();
59 }
60 return $link;
61 }, 10, 3 );
62 }
63
64 public function init_extension()
65 {
66 $this->title = __('Press Bar', 'notificationx');
67 $this->module_title = __('Notification Bar', 'notificationx');
68 $this->themes = [
69 'theme-two' => [
70 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-two.jpg',
71 'column' => "12",
72 'defaults' => [
73 'enable_countdown' => 0,
74 'nx_bar_border_radius_left' => 0,
75 'nx_bar_border_radius_right' => 0,
76 'nx_bar_border_radius_top' => 0,
77 'nx_bar_border_radius_bottom' => 0,
78 'button_icon' => 'none',
79 'bar_bg_color' => '#5807a2',
80 // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings -- Reviewed for the NotificationX codebase: acceptable in this context.
81 'press_content' => __('<b>We\'re excited to introduce something new!</b>','notificationx'),
82 'button_text' => __('Show Me!', 'notificationx'),
83 'link_button_bg_color' => '#9c2bff',
84 'link_button_text_color' => '#ffffff',
85 'bar_counter_bg' => '',
86 ],
87 ],
88 'theme-one' => [
89 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-one.jpg',
90 'column' => "12",
91 'defaults' => [
92 'enable_countdown' => 1,
93 'nx_bar_border_radius_left' => 0,
94 'nx_bar_border_radius_right' => 0,
95 'nx_bar_border_radius_top' => 0,
96 'nx_bar_border_radius_bottom' => 0,
97 'button_icon' => 'none',
98 'bar_bg_color' => '#dddddd',
99 'press_content' => __('<p style="color: #000;"><span>Save Big & Get Lifetime unlimited</span> <strong>NotificationX</strong> for $99!</p>','notificationx'),
100 'button_text' => __('Get Offer', 'notificationx'),
101 'link_button_bg_color' => '#000',
102 'link_button_text_color' => '#ffffff',
103 'bar_counter_bg' => '#262626',
104 'bar_counter_text_color' => '#fff'
105 ],
106 ],
107 'theme-three' => [
108 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-three.jpg',
109 'column' => "12",
110 'defaults' => [
111 'enable_countdown' => 1,
112 'nx_bar_border_radius_left' => 0,
113 'nx_bar_border_radius_right' => 0,
114 'nx_bar_border_radius_top' => 0,
115 'nx_bar_border_radius_bottom' => 0,
116 'button_icon' => 'none',
117 'bar_bg_color' => '#3f4462',
118 'press_content' => __('<b>Save Big & Get Lifetime unlimited <strong>NotificationX</strong> for $99</b>','notificationx'),
119 'button_text' => __('Get Offer!', 'notificationx'),
120 'link_button_bg_color' => '#6A4BFF',
121 'link_button_text_color' => '#ffffff',
122 'bar_counter_bg' => '#6549fe',
123 'bar_counter_text_color' => '#fff',
124 ],
125 ],
126 'theme-four' => [
127 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-four-preview.webp',
128 'column' => "12",
129 'defaults' => [
130 'enable_countdown' => 1,
131 // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings -- Reviewed for the NotificationX codebase: acceptable in this context.
132 'press_content' => __('<p><span style="color: #F54747;">4 Years</span> Of Seamlessly Creating NotificationX!</p>','notificationx'),
133 'button_text' => __('Grab Deal Now', 'notificationx'),
134 'link_button_bg_color' => '#ffffff',
135 'link_button_text_color' => '#000',
136 'nx_bar_border_radius_left' => 16,
137 'nx_bar_border_radius_right' => 16,
138 'nx_bar_border_radius_top' => 16,
139 'nx_bar_border_radius_bottom' => 16,
140 'button_icon' => 'none',
141 'bar_counter_bg' => 'rgba(255, 255, 255, 0.5019607843)',
142 'bar_counter_text_color' => '#230600',
143 ],
144 ],
145 'theme-five' => [
146 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-five-preview.webp',
147 'column' => "12",
148 'defaults' => [
149 // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings -- Reviewed for the NotificationX codebase: acceptable in this context.
150 'press_content' => __('<p><span style="color: #fff;">🎁 Flash 30%</span> Sale is On Now! Don’t miss out on this opportunity</p>','notificationx'),
151 'enable_countdown' => 1,
152 'nx_bar_border_radius_left' => 16,
153 'nx_bar_border_radius_right' => 16,
154 'nx_bar_border_radius_top' => 16,
155 'nx_bar_border_radius_bottom' => 16,
156 'button_icon' => 'none',
157 'button_text' => __('Save $20', 'notificationx'),
158 'link_button_bg_color' => '#2e72ff',
159 'link_button_text_color' => '#ffffff',
160 'bar_bg_color' => '',
161 'bar_counter_bg' => 'transparent',
162 'bar_counter_text_color' => '#fff',
163 ],
164 ],
165 'theme-six' => [
166 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-six-preview.webp',
167 'column' => "12",
168 'defaults' => [
169 // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings -- Reviewed for the NotificationX codebase: acceptable in this context.
170 'press_content' => __('<p><span style="color: #000;">🎁 Flash 30%</span> Sale is On Now! Don’t miss out on this opportunity</p>','notificationx'),
171 'enable_countdown' => 1,
172 'nx_bar_border_radius_left' => 16,
173 'nx_bar_border_radius_right' => 16,
174 'nx_bar_border_radius_top' => 16,
175 'nx_bar_border_radius_bottom' => 16,
176 'button_text' => __('Shop Now', 'notificationx'),
177 'bar_bg_color' => 'linear-gradient(90deg, #94F9FC 0%, #E2DAFE 100%)',
178 'button_icon' => 'shop-icon.svg',
179 'bar_counter_bg' => 'rgba(255, 255, 255, 0.5019607843)',
180 'bar_counter_text_color' => '#230600',
181 ],
182 ],
183 'theme-seven' => [
184 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-seven-preview.webp',
185 'column' => "12",
186 'defaults' => [
187 // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings -- Reviewed for the NotificationX codebase: acceptable in this context.
188 'press_content' => __('<p><span style="color: #9F7800;">4 years</span> Of Seamlessly Creating NotificationX!</p>','notificationx'),
189 'enable_countdown' => 0,
190 'nx_bar_border_radius_left' => 0,
191 'nx_bar_border_radius_right' => 0,
192 'nx_bar_border_radius_top' => 0,
193 'nx_bar_border_radius_bottom' => 0,
194 'button_text' => __('Shop Now', 'notificationx'),
195 'bar_bg_color' => '#F4F1E8',
196 'button_icon' => 'shop_now.svg',
197 'link_button_bg_color' => '#e3dac2',
198 'link_button_text_color' => '#000',
199 'bar_counter_bg' => '',
200 ],
201 ],
202 ];
203 $this->bar_themes = array(
204 'theme-one' => [
205 'label' => 'theme-one',
206 'value' => 'theme-one',
207 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-one.jpg',
208 'column' => '12',
209 "title" => "Nx Theme One",
210 'enable_coupon' => true,
211 ],
212 'theme-two' => [
213 'label' => 'theme-two',
214 'value' => 'theme-two',
215 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-two.jpg',
216 'column' => '12',
217 "title" => "Nx Theme Two",
218 ],
219 'theme-three' => [
220 'label' => 'theme-three',
221 'value' => 'theme-three',
222 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-three.jpg',
223 'column' => '12',
224 "title" => "Nx Theme Three",
225 ],
226 'theme-four' => [
227 'label' => 'theme-four',
228 'value' => 'theme-four',
229 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-four.jpg',
230 'column' => '12',
231 "title" => "Theme Four - Cookies Layout",
232 ],
233 'theme-five' => [
234 'label' => 'theme-five',
235 'value' => 'theme-five',
236 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-five.jpg',
237 'column' => '12',
238 "title" => "Theme Five - Cookies Layout",
239 ],
240 );
241 $this->block_themes = array(
242 'theme-one' => [
243 'label' => 'theme-one',
244 'value' => 'theme-one',
245 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-one.png',
246 'column' => '12',
247 "title" => "Nx Theme One",
248 'position' => 'top',
249 ],
250 'theme-two' => [
251 'label' => 'theme-two',
252 'value' => 'theme-two',
253 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-two.png',
254 'column' => '12',
255 "title" => "Nx Theme Two",
256 'position' => 'top',
257 ],
258 'theme-three' => [
259 'label' => 'theme-three',
260 'value' => 'theme-three',
261 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-three.png',
262 'column' => '12',
263 "title" => "Nx Theme Three",
264 'position' => 'top',
265 ],
266 'theme-four' => [
267 'label' => 'theme-four',
268 'value' => 'theme-four',
269 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-four.png',
270 'column' => '12',
271 "title" => "Nx Theme Four",
272 'position' => 'top',
273 ],
274 'theme-five' => [
275 'label' => 'theme-five',
276 'value' => 'theme-five',
277 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-one.jpg',
278 'column' => '12',
279 "title" => "Nx Theme Five",
280 "popup" => $this->popup,
281 'position' => 'top',
282 ],
283 'theme-six' => [
284 'label' => 'theme-six',
285 'value' => 'theme-six',
286 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-two.jpg',
287 'column' => '12',
288 "title" => "Nx Theme Six",
289 "popup" => $this->popup,
290 'position' => 'top',
291 ],
292 'theme-seven' => [
293 'label' => 'theme-seven',
294 'value' => 'theme-seven',
295 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-three.jpg',
296 'column' => '12',
297 "title" => "Nx Theme Seven",
298 "popup" => $this->popup,
299 'position' => 'top',
300 ],
301 );
302 // check if essential blocks is installed.
303 }
304
305 public function init() {
306 parent::init();
307 add_filter("nx_theme_preview_{$this->id}", [$this, 'theme_preview'], 10, 2);
308 add_filter("nx_get_post", [$this, 'nx_get_post'], 9);
309 add_filter("nx_delete_post", [$this, 'nx_delete_post'], 10, 2);
310 add_filter("nx_filtered_post", [$this, 'add_scripts'], 10, 2);
311 }
312
313 /**
314 * This functions is hooked
315 *
316 * @return void
317 */
318 public function admin_actions() {
319 parent::admin_actions();
320 add_filter('templately_cloud_push_post_type', [$this, 'templately_cloud_push_post_type']);
321 }
322
323 /**
324 * This functions is hooked
325 *
326 * @hooked nx_public_action
327 * @return void
328 */
329 public function public_actions() {
330 parent::public_actions();
331 // add_action('wp_head', [$this, 'print_bar_notice'], 100);
332 add_filter("nx_filtered_data_{$this->id}", array($this, 'insert_views'), 11, 3);
333 add_filter("rocket_rucss_safelist", array($this, 'rocket_rucss_safelist'), 11);
334 }
335
336
337 public function init_fields() {
338 parent::init_fields();
339 add_filter('nx_design_tab_fields', [$this, 'design_tab_fields']);
340 add_filter('nx_design_tab_fields', [$this, 'design_tab_presets_fields']);
341 add_filter('nx_design_tab_fields', [$this, 'design_tab_fields_for_button'], 20);
342 add_filter('nx_customize_fields', [$this, 'customize_fields']);
343 add_filter('nx_content_fields', [$this, 'content_fields'], 22);
344 add_filter('nx_display_fields', [$this, 'hide_image_field']);
345 add_filter('nx_display_fields', [$this, 'display_fields']);
346 add_filter('nx_source_trigger', [$this, '_source_trigger'], 20);
347 }
348
349 public function save_post($post, $data, $nx_id) {
350 unset($post['data']['is_elementor']);
351 unset($post['data']['is_confirmed']);
352 unset($post['data']['is_gutenberg']);
353 unset($post['data']['is_gb_confirmed']);
354 $post['data']['countdown_start_date'] = !empty( $data['countdown_start_date'] ) ? Helper::mysql_time($data['countdown_start_date']) : '';
355 $post['data']['countdown_end_date'] = !empty( $data['countdown_end_date'] ) ? Helper::mysql_time($data['countdown_end_date']) : '';
356 $post['data']['countdown_rand'] = wp_rand();
357 return $post;
358 }
359
360 public function saved_post($post, $data, $nx_id) {
361 if(!empty($data['elementor_id'])){
362 $title = !empty($post['title']) ? $post['title'] : $nx_id;
363 $my_post = array(
364 'ID' => $data['elementor_id'],
365 'post_title' => "NxBar: " . $title,
366 );
367 wp_update_post( $my_post );
368 }
369 }
370
371 public function theme_preview($url, $post) {
372 if ( !empty($post['gutenberg_id']) && !empty($post['gutenberg_bar_theme']) && !empty($this->block_themes[$post['gutenberg_bar_theme']])) {
373 return $this->block_themes[$post['gutenberg_bar_theme']]['icon'];
374 }
375 if (!empty($post['elementor_id']) && !empty($post['elementor_bar_theme']) && !empty($this->bar_themes[$post['elementor_bar_theme']])) {
376 return $this->bar_themes[$post['elementor_bar_theme']]['icon'];
377 }
378 return $url;
379 }
380
381 /**
382 * Get themes for the extension.
383 *
384 *
385 * @param array $args Settings arguments.
386 * @return mixed
387 */
388 public function insert_views($content, $settings) {
389 Analytics::get_instance()->insert_views([], $settings);
390 return $content;
391 }
392
393 /**
394 * Get themes for the extension.
395 *
396 *
397 * @param array $args Settings arguments.
398 * @return mixed
399 */
400 public function _source_trigger($triggers) {
401 $triggers[$this->id]['position'] = "@position:top";
402 return $triggers;
403 }
404
405 /**
406 * NX Bar Presets tab fields for button.
407 *
408 * @param array $fields
409 * @return array
410 */
411 public function design_tab_presets_fields($fields) {
412 $import_design = [];
413 $import_design = &$fields['themes']['fields']['themes_section']['fields']['themes_tab']['fields'];
414 $import_design[] = [
415 'label' => __("Presets", 'notificationx'),
416 'name' => 'for_desktop',
417 'id' => 'for_desktop',
418 'type' => 'section',
419 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/icons/nxbar-presets-icon.svg',
420 'rules' => Rules::is('source', $this->id),
421 ];
422 $import_design[] = [
423 'label' => __("Custom", 'notificationx'),
424 'name' => 'nxbar_custom',
425 'id' => 'nxbar_custom',
426 'type' => 'section',
427 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/icons/nxbar-custom-tab.svg',
428 'rules' => Rules::is('source', $this->id),
429 'fields' => [
430 'nxbar_custom' => [
431 'label' => __("Custom", 'notificationx'),
432 'name' => 'nxbar_custom',
433 'id' => 'nxbar_custom',
434 'type' => 'section',
435 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/responsive/desktop.svg',
436 'fields' => [
437 'nxbar_custom_fields' => [
438 'name' => "nxbar_custom_fields",
439 'type' => "nxbar-custom",
440 'label' => __('NX Bar', 'notificationx'),
441 'priority' => 10,
442 ],
443 ]
444 ],
445 ]
446 ];
447 $import_design[] = [
448 'label' => __("Build With AI", 'notificationx'),
449 'name' => 'nxbar_build_with_ai',
450 'id' => 'nxbar_build_with_ai',
451 'type' => 'section',
452 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/icons/build-with-ai-icon.svg',
453 'rules' => Rules::is('source', $this->id),
454 'fields' => [
455 'nxbar_build_with_ai' => [
456 'label' => __("Build With AI", 'notificationx'),
457 'name' => 'nxbar_build_with_ai',
458 'id' => 'nxbar_build_with_ai',
459 'type' => 'section',
460 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/responsive/desktop.svg',
461 'fields' => [
462 'nxbar_build_with_ai_fields' => [
463 'name' => "nxbar_build_with_ai_fields",
464 'type' => "nxbar-build_with_ai",
465 'label' => __('NX Bar', 'notificationx'),
466 'priority' => 10,
467 ],
468 ]
469 ],
470 ]
471 ];
472 return $fields;
473 }
474
475 /**
476 * NX Bar design tab fields for button.
477 *
478 * @param array $fields
479 * @return array
480 */
481 public function design_tab_fields_for_button($fields) {
482 $_fields = &$fields['advance_design_section']['fields'];
483 $border_fields = [
484 'nx_bar_border_radius' => [
485 'name' => "nx_bar_border_radius",
486 'type' => "section",
487 'label' => __('Border Radius', 'notificationx'),
488 'fields' => [
489 [
490 'help' => __('Left', 'notificationx'),
491 'name' => "nx_bar_border_radius_left",
492 'type' => "number",
493 'default' => '0',
494 'description' => 'px',
495 ],
496 [
497 'help' => __('Right', 'notificationx'),
498 'name' => "nx_bar_border_radius_right",
499 'type' => "number",
500 'default' => '0',
501 'description' => 'px',
502 ],
503 [
504 'help' => __('Top', 'notificationx'),
505 'name' => "nx_bar_border_radius_top",
506 'type' => "number",
507 'default' => '0',
508 'description' => 'px',
509 ],
510 [
511 'help' => __('Bottom', 'notificationx'),
512 'name' => "nx_bar_border_radius_bottom",
513 'type' => "number",
514 'default' => '0',
515 'description' => 'px',
516 ],
517 ]
518 ],
519 ];
520 if( !empty($_fields['link_button_design']['fields'] ) ) {
521 $_fields['link_button_design']['fields'] = array_merge( $_fields['link_button_design']['fields'], $border_fields);
522 }
523 return $fields;
524 }
525
526 /**
527 * This method is an implementable method for All Extension coming forward.
528 *
529 * @param array $args Settings arguments.
530 * @return mixed
531 */
532 public function design_tab_fields($fields) {
533 $_fields = &$fields['advance_design_section']['fields'];
534 $_fields['design'] = Rules::is('source', $this->id, true, $_fields['design']);
535 $_fields['typography'] = Rules::is('source', $this->id, true, $_fields['typography']);
536 $_fields['image-appearance'] = Rules::is('source', $this->id, true, $_fields['image-appearance']);
537 $_fields['bar_editor'] = [
538 'label' => "Editor",
539 'name' => "bar_editor",
540 'type' => "section",
541 'priority' => 2,
542 'rules' => ["and", ['is', 'source', $this->id], ['is', 'advance_edit', true]],
543 'fields' => [],
544 ];
545 $_fields["bar_design"] = [
546 // @todo Move to extension.
547 'label' => "Design",
548 'name' => "bar_design",
549 'type' => "section",
550 'priority' => 5,
551 'rules' => ["and", ['is', 'source', $this->id], ['is', 'advance_edit', true]],
552 'fields' => [
553 [
554 'label' => __('Background Color', 'notificationx'),
555 'name' => "bar_bg_color",
556 'type' => "gradientpicker",
557 ],
558 [
559 'label' => __("Background Image", 'notificationx'),
560 'name' => "bar_bg_image",
561 'button' => __('Upload', 'notificationx'),
562 'type' => "media",
563 'default' => "",
564 ],
565 [
566 'label' => __('Text Color', 'notificationx'),
567 'name' => "bar_text_color",
568 'type' => "colorpicker",
569 ],
570 // [
571 // 'label' => __('Button Background Color', 'notificationx'),
572 // 'name' => "bar_btn_bg",
573 // 'type' => "colorpicker",
574 // ],
575 // [
576 // 'label' => __('Button Text Color', 'notificationx'),
577 // 'name' => "bar_btn_text_color",
578 // 'type' => "colorpicker",
579 // ],
580 [
581 'label' => __('Countdown Background Color', 'notificationx'),
582 'name' => "bar_counter_bg",
583 'type' => "colorpicker",
584 ],
585 [
586 'label' => __('Countdown Text Color', 'notificationx'),
587 'name' => "bar_counter_text_color",
588 'type' => "colorpicker",
589 ],
590 [
591 'label' => __('Close Button Color', 'notificationx'),
592 'name' => "bar_close_color",
593 'type' => "colorpicker",
594 ],
595 [
596 'label' => __('Close Button Size', 'notificationx'),
597 'name' => "bar_close_button_size",
598 'type' => "number",
599 'default' => '10',
600 'description' => 'px',
601 ],
602 [
603 'name' => "close_button_section",
604 'type' => "section",
605 'fields' => [
606 [
607 'name' => 'closed_button_section_label',
608 'type' => 'section',
609 'fields' => [
610 [
611 'name' => 'closed_button_section_label_text',
612 'type' => 'message',
613 'class' => 'nx-close-button-label',
614 'html' => true,
615 'message' => __('Close Button Position', 'notificationx'),
616 ]
617 ]
618 ],
619 [
620 'name' => 'closed_button_section_fields',
621 'type' => 'section',
622 'fields' => [
623 [
624 'label' => __('Close Button Position', 'notificationx'),
625 'name' => "bar_close_position",
626 'type' => "select",
627 'default' => 'right',
628 'options' => GlobalFields::get_instance()->normalize_fields([
629 'left' => __('Left', 'notificationx'),
630 'right' => __('Right', 'notificationx'),
631 ]),
632 ],
633 [
634 'label' => __('Close Button Position Top', 'notificationx'),
635 'help' => __('Top', 'notificationx'),
636 'name' => "bar_position_left_top",
637 'type' => "number",
638 'default' => '15',
639 'description' => 'px',
640 'rules' => Rules::logicalRule([
641 Rules::is('bar_close_position', 'left'),
642 ]),
643 ],
644 [
645 'label' => __('Close Button Position Left', 'notificationx'),
646 'help' => __('Left', 'notificationx'),
647 'name' => "bar_position_left_left",
648 'type' => "number",
649 'default' => '15',
650 'description' => 'px',
651 'rules' => Rules::logicalRule([
652 Rules::is('bar_close_position', 'left'),
653 ]),
654 ],
655 [
656 'label' => __('Close Button Position Top', 'notificationx'),
657 'help' => __('Top', 'notificationx'),
658 'name' => "bar_position_right_top",
659 'type' => "number",
660 'default' => '15',
661 'description' => 'px',
662 'rules' => Rules::logicalRule([
663 Rules::is('bar_close_position', 'right'),
664 ]),
665 ],
666 [
667 'label' => __('Close Button Position Right', 'notificationx'),
668 'help' => __('Right', 'notificationx'),
669 'name' => "bar_position_right_right",
670 'type' => "number",
671 'default' => '15',
672 'description' => 'px',
673 'rules' => Rules::logicalRule([
674 Rules::is('bar_close_position', 'right'),
675 ]),
676 ],
677 ]
678 ]
679 ]
680 ],
681 ],
682 ];
683
684 $_fields["bar_typography"] = [
685 // @todo Move to extension.
686 'label' => __('Typography', 'notificationx'),
687 'name' => "bar_typography",
688 'type' => "section",
689 'priority' => 10,
690 'rules' => ["and", ['is', 'source', $this->id], ['is', 'advance_edit', true]],
691 'fields' => [
692 [
693 'label' => __('Font Size', 'notificationx'),
694 'name' => "bar_font_size",
695 'type' => "number",
696 'default' => '13',
697 'min' => 1,
698 'priority' => 5,
699 'description' => 'px',
700 'help' => __('This font size will be applied for <mark>first</mark> row', 'notificationx'),
701 ],
702 ],
703 ];
704
705 $is_installed = Helper::is_plugin_installed('elementor/elementor.php');
706 $install_activate_text = $is_installed ? __("Activate", 'notificationx') : __("Install", 'notificationx');
707
708
709
710 // $fields['themes']['fields'][] = array(
711 // 'name' => 'nx-bar_with_elementor_install_message',
712 // 'type' => 'message',
713 // 'class' => 'nx-warning',
714 // 'html' => true,
715 // 'message' => sprintf(__("To Design Notification Bar with <strong>Elementor Page Builder</strong>, You need to %s the Elementor first: &nbsp;&nbsp;&nbsp;", 'notificationx'), $install_activate_text),
716 // 'rules' => Rules::logicalRule([
717 // Rules::is('is_elementor', false),
718 // Rules::is('gutenberg_id', false),
719 // Rules::is('source', $this->id),
720 // ]),
721 // );
722
723 $fields['themes']['fields']['nxbar_with_elementor'] = [
724 'name' => 'nxbar_with_elementor',
725 'type' => 'section',
726 'fields' => [],
727 'rules' => Rules::logicalRule([
728 Rules::is('elementor_edit_link', false, true),
729 Rules::isOfType('elementor_edit_link', 'string'),
730 Rules:: is('elementor_id', false, true),
731 ]),
732 ];
733
734 $fields['themes']['fields']['nxbar_with_gutenberg'] = [
735 'name' => 'nxbar_with_gutenberg',
736 'type' => 'section',
737 'fields' => [],
738 'rules' => Rules::logicalRule([
739 Rules::is('gutenberg_edit_link', false, true),
740 Rules::isOfType('gutenberg_edit_link', 'string'),
741 Rules:: is('gutenberg_id', false, true),
742 ]),
743 ];
744
745 $fields['themes']['fields']['nx_bar_import_design'] = [
746 'name' => 'nx_bar_import_design',
747 'type' => 'section',
748 'fields' => [],
749 'rules' => Rules::logicalRule([
750 Rules:: is('source', $this->id),
751 ]),
752 ];
753
754 $import_design = [];
755 // $import_design = $fields['advance_design_section']['fields'];
756 $import_design = &$fields['themes']['fields']['nx_bar_import_design']['fields'];
757
758 $import_design[] = [
759 'name' => 'elementor_edit_link',
760 'type' => 'button',
761 'text' => __('Edit With Elementor', 'notificationx'),
762 'href' => -1,
763 'priority' => 1,
764 'target' => '_blank',
765 'rules' => Rules::logicalRule([
766 Rules::is('elementor_edit_link', false, true),
767 Rules::isOfType('elementor_edit_link', 'string'),
768 Rules:: is('elementor_id', false, true),
769 // Rules:: is('is_elementor', true),
770 // Rules:: is('source', $this->id),
771 ]),
772 ];
773 $import_design[] = [
774 'name' => 'nx-bar_with_elementor-remove',
775 'type' => 'button',
776 'priority' => 2,
777 'text' => __('Remove', 'notificationx'),
778 'rules' => Rules::logicalRule([
779 Rules::is('elementor_id', false, true),
780 Rules::is('is_elementor', true),
781 Rules::is('source', $this->id),
782 ]),
783 'ajax' => [
784 'on' => 'click',
785 'api' => '/notificationx/v1/elementor/remove',
786 'data' => [
787 'elementor_id' => '@elementor_id',
788 ],
789 'hideSwal' => true,
790 ],
791 'trigger' => [
792 [
793 'type' => 'setFieldValue',
794 'action' => [
795 'elementor_id' => false,
796 'elementor_edit_link' => '',
797 'is_confirmed' => false,
798 'themes' => 'press_bar_theme-one',
799 ]
800 ],
801 ],
802 ];
803
804 $import_design[] = [
805 'name' => 'nx-bar_with_elementor',
806 'type' => 'modal',
807 'button' => [
808 'name' => 'build_with_elementor',
809 'text' => __('Build With Elementor', 'notificationx'),
810 'trigger' => [
811 [
812 'type' => 'setFieldValue',
813 'action' => [
814 'import_elementor_theme' => false
815 ]
816 ],
817 ],
818 ],
819 'confirm_button' => [
820 'type' => 'button',
821 'name' => 'import_elementor_theme',
822 'group' => true,
823 'fields' => [
824 [
825 'type' => 'button',
826 'name' => 'import_elementor_theme',
827 "default" => false,
828 'text' => [
829 'normal' => __('Import', 'notificationx'),
830 'saved' => __('Import', 'notificationx'),
831 'loading' => __('Importing...', 'notificationx'),
832 ],
833 'ajax' => [
834 'on' => 'click',
835 'api' => '/notificationx/v1/elementor/import',
836 'data' => [
837 'theme_id' => '@elementor_bar_theme',
838 ],
839 'trigger' => '@is_confirmed:true',
840 'hideSwal' => true,
841 ],
842 'rules' => Rules::is('is_confirmed', true, true),
843 ],
844 [
845 'type' => 'button',
846 'name' => 'import_elementor_theme_next',
847 "default" => false,
848 'text' => __('Next', 'notificationx'),
849 'rules' => Rules::is('is_confirmed', true),
850 'trigger' => [
851 [
852 'type' => 'setContext',
853 'action' => [
854 'config.active' => 'display_tab'
855 ]
856 ],
857 [
858 'type' => 'setFieldValue',
859 'action' => [
860 'import_elementor_theme_next' => true
861 ]
862 ],
863 ],
864 ],
865 ],
866 ],
867 'cancel' => "import_elementor_theme_next",
868 'body' => [
869 'header' => __('Choose Your ', 'notificationx'),
870 'fields' => [
871 'themes' => [
872 'type' => 'radio-card',
873 'name' => "elementor_bar_theme",
874 'style' => [
875 'label' => [
876 'position' => 'top'
877 ]
878 ],
879 'rules' => Rules::is('is_confirmed', true, true),
880 'default' => 'theme-one',
881 'options' => $this->bar_themes,
882 ],
883 'test' => [
884 'name' => 'builder_modal_message',
885 'type' => 'message',
886 'message' => 'Hello World',
887 'rules' => Rules::is('is_confirmed', true)
888 ]
889 ],
890 ],
891 'rules' => Rules::logicalRule([
892 Rules::is('gutenberg_id', false),
893 Rules::is('elementor_id', false),
894 Rules::is('is_elementor', true),
895 Rules::is('is_confirmed', true, true),
896 Rules::is('source', $this->id)
897 ]),
898 ];
899
900 $import_design[] = [
901 'name' => 'nx-bar_with_elementor_install',
902 'type' => 'button',
903 'priority' => 3,
904 'text' => [
905 'normal' => $is_installed ? __('Activate Elementor', 'notificationx') : __('Install Elementor', 'notificationx'),
906 'saved' => $is_installed ? __('Activated Elementor', 'notificationx') : __('Installed Elementor', 'notificationx'),
907 'loading' => $is_installed ? __('Activating Elementor...', 'notificationx') : __('Installing Elementor...', 'notificationx'),
908 ],
909 'style' => [
910 'description' => [
911 'position' => 'left'
912 ]
913 ],
914 // 'classes' => "nx-ele-bar-button nx-bar_with_elementor_install nx-on-click-install",
915 'rules' => Rules::logicalRule([
916 Rules::is('is_elementor', false),
917 Rules::is('gutenberg_id', false),
918 Rules::is('source', $this->id),
919 ]),
920 // 'data-nonce' => wp_create_nonce('wpdeveloper_upsale_core_install_notificationx'),
921 // 'data-slug' => 'elementor',
922 // 'data-plugin_file' => 'elementor.php',
923 'ajax' => [
924 'on' => 'click',
925 'api' => '/notificationx/v1/core-install',
926 'data' => [
927 'source' => $this->id,
928 'slug' => "elementor",
929 'file' => "elementor.php",
930 'is_installed' => $is_installed,
931 ],
932 'swal' => [
933 'icon' => 'success',
934 'text' => __('Successfully Activated', 'notificationx'),
935 ],
936 'trigger' => '@is_elementor:true',
937 ],
938 ];
939 $import_design[] = [
940 'name' => 'is_elementor',
941 'type' => 'hidden',
942 'default' => class_exists('\Elementor\Plugin'),
943 'rules' => Rules::is('source', $this->id),
944 ];
945 $import_design[] = [
946 'name' => 'elementor_id',
947 'type' => 'hidden',
948 'default' => false,
949 'rules' => Rules::is('source', $this->id),
950 ];
951 $import_design[] = [
952 'type' => 'hidden',
953 'name' => 'is_confirmed',
954 'default' => false
955 ];
956 // $import_design[] = [
957 // 'name' => 'elementor_edit_link',
958 // 'type' => 'hidden',
959 // 'rules' => Rules::is('source', $this->id),
960 // ];
961
962
963 // Block pattern
964
965 $import_design[] = [
966 'name' => 'gutenberg_edit_link',
967 'type' => 'button',
968 'text' => __('Edit With Gutenberg', 'notificationx'),
969 'href' => -1,
970 'priority' => 4,
971 'target' => '_blank',
972 'rules' => Rules::logicalRule([
973 Rules::is('gutenberg_edit_link', false, true),
974 Rules::isOfType('gutenberg_edit_link', 'string'),
975 Rules:: is('gutenberg_id', false, true),
976 // Rules:: is('is_gutenberg', true),
977 // Rules:: is('source', $this->id),
978 ]),
979 ];
980 $import_design[] = [
981 'name' => 'nx-bar_with_gutenberg-remove',
982 'type' => 'button',
983 'text' => __('Remove', 'notificationx'),
984 'priority' => 5,
985 'rules' => Rules::logicalRule([
986 Rules::is('gutenberg_id', false, true),
987 Rules::is('is_gutenberg', true),
988 Rules::is('source', $this->id),
989 ]),
990 'ajax' => [
991 'on' => 'click',
992 'api' => '/notificationx/v1/gutenberg/remove',
993 'data' => [
994 'gutenberg_id' => '@gutenberg_id',
995 ],
996 'hideSwal' => true,
997 ],
998 'trigger' => [
999 [
1000 'type' => 'setFieldValue',
1001 'action' => [
1002 'gutenberg_id' => false,
1003 'gutenberg_edit_link' => '',
1004 'is_gb_confirmed' => false,
1005 'themes' => 'press_bar_theme-one',
1006 ]
1007 ],
1008 ],
1009 ];
1010
1011 $import_design[] = [
1012 'name' => 'nx-bar_with_gutenberg',
1013 'type' => 'modal',
1014 'button' => [
1015 'name' => 'build_with_gutenberg',
1016 'text' => __('Build With Gutenberg', 'notificationx'),
1017 'trigger' => [
1018 [
1019 'type' => 'setFieldValue',
1020 'action' => [
1021 'import_gutenberg_theme' => false
1022 ]
1023 ],
1024 ],
1025 ],
1026 'confirm_button' => [
1027 'type' => 'button',
1028 'name' => 'import_gutenberg_theme',
1029 'group' => true,
1030 'fields' => [
1031 [
1032 'type' => 'button',
1033 'name' => 'import_gutenberg_theme',
1034 "default" => false,
1035 'text' => [
1036 'normal' => __('Import', 'notificationx'),
1037 'saved' => __('Import', 'notificationx'),
1038 'loading' => __('Importing...', 'notificationx'),
1039 ],
1040 'ajax' => [
1041 'on' => 'click',
1042 'api' => '/notificationx/v1/gutenberg/import',
1043 'data' => [
1044 'theme_id' => '@gutenberg_bar_theme',
1045 ],
1046 'trigger' => '@is_gb_confirmed:true',
1047 'hideSwal' => true,
1048 ],
1049 'rules' => Rules::is('is_gb_confirmed', true, true),
1050 ],
1051 [
1052 'type' => 'button',
1053 'name' => 'import_gutenberg_theme_next',
1054 "default" => false,
1055 'text' => __('Next', 'notificationx'),
1056 'rules' => Rules::is('is_gb_confirmed', true),
1057 'trigger' => [
1058 [
1059 'type' => 'setContext',
1060 'action' => [
1061 'config.active' => 'display_tab'
1062 ]
1063 ],
1064 [
1065 'type' => 'setFieldValue',
1066 'action' => [
1067 'import_gutenberg_theme_next' => true
1068 ]
1069 ],
1070 ],
1071 ],
1072 ],
1073 ],
1074 'cancel' => "import_gutenberg_theme_next",
1075 'body' => [
1076 'header' => __('Choose Your ', 'notificationx'),
1077 'fields' => [
1078 'themes' => [
1079 'type' => 'radio-card',
1080 'name' => "gutenberg_bar_theme",
1081 'style' => [
1082 'label' => [
1083 'position' => 'top'
1084 ]
1085 ],
1086 'rules' => Rules::is('is_gb_confirmed', true, true),
1087 'default' => 'theme-one',
1088 'options' => $this->block_themes,
1089 ],
1090 'test' => [
1091 'name' => 'builder_modal_message',
1092 'type' => 'message',
1093 'message' => 'Hello World',
1094 'rules' => Rules::is('is_gb_confirmed', true)
1095 ]
1096 ],
1097 ],
1098 'rules' => Rules::logicalRule([
1099 Rules::is('elementor_id', false),
1100 Rules::is('gutenberg_id', false),
1101 Rules::is('is_gutenberg', true),
1102 Rules::is('is_gb_confirmed', true, true),
1103 Rules::is('source', $this->id)
1104 ]),
1105 ];
1106 $import_design[] = [
1107 'name' => 'is_gutenberg',
1108 'type' => 'hidden',
1109 'default' => function_exists('use_block_editor_for_post_type') ? use_block_editor_for_post_type('nx_bar_eb') : false,
1110 'rules' => Rules::is('source', $this->id),
1111 ];
1112 $import_design[] = [
1113 'name' => 'gutenberg_id',
1114 'type' => 'hidden',
1115 'default' => false,
1116 'rules' => Rules::is('source', $this->id),
1117 ];
1118 $import_design[] = [
1119 'type' => 'hidden',
1120 'name' => 'is_gb_confirmed',
1121 'default' => false
1122 ];
1123 $_fields['bar_editor']['fields'] = array_merge($_fields['bar_editor']['fields']);
1124 return $fields;
1125 }
1126
1127 /**
1128 * Display fields
1129 */
1130 public function display_fields( $fields ) {
1131 $fields['visibility']['fields']['bar_reappearance'] = array(
1132 'label' => __( 'Bar Reappearance', 'notificationx' ),
1133 'type' => 'select',
1134 'name' => 'bar_reappearance',
1135 'default' => 'show_welcomebar_every_page',
1136 'rules' => Rules::logicalRule([
1137 Rules::is('source', $this->id),
1138 ]),
1139 'options' => GlobalFields::get_instance()->normalize_fields([
1140 'dont_show_welcomebar' => __( "Don't show the Bar again for the user", 'notificationx' ),
1141 'show_welcomebar_next_visit' => __( 'Show the Bar again when the user visits the website next time', 'notificationx' ),
1142 'show_welcomebar_every_page' => __( 'Show the Bar when the user refreshes/goes to another page', 'notificationx' ),
1143 ]),
1144 );
1145 $fields['visibility']['fields']['bar_cache_duration_for_dont_show'] = [
1146 'label' => __( 'Cache Duration for "Don\'t show again"', 'notificationx' ),
1147 'name' => 'bar_cache_duration_for_dont_show',
1148 'type' => 'number',
1149 'default' => 10,
1150 'min' => 1,
1151 'max' => 365,
1152 'step' => 1,
1153 'description' => __('Days', 'notificationx'),
1154 'rules' => Rules::logicalRule([
1155 Rules::is('bar_reappearance', 'dont_show_welcomebar'),
1156 Rules::is('source', $this->id),
1157 ]),
1158 ];
1159 return $fields;
1160 }
1161
1162 /**
1163 * Get All Roles
1164 * dynamically
1165 *
1166 * @return array
1167 */
1168 public function get_roles() {
1169 $roles = wp_roles()->role_names;
1170 return $roles;
1171 }
1172
1173 /**
1174 * This method is an implementable method for All Extension coming forward.
1175 *
1176 * @param array $args Settings arguments.
1177 * @return mixed
1178 */
1179 public function customize_fields($fields) {
1180 $wp_roles = $this->get_roles();
1181
1182 $fields['queue_management'] = Rules::is('source', $this->id, true, $fields['queue_management']);
1183 $_fields = &$fields["appearance"]['fields'];
1184 $conversion_position = &$_fields['position']['options'];
1185
1186 $_fields['size'] = Rules::is('source', $this->id, true, $_fields['size']);
1187 $conversion_position['bottom_left'] = Rules::is('source', $this->id, true, $conversion_position['bottom_left']);
1188 $conversion_position['bottom_right'] = Rules::is('source', $this->id, true, $conversion_position['bottom_right']);
1189
1190 if (isset($fields['sound_section'])) {
1191 $fields['sound_section'] = Rules::includes('source', $this->id, true, $fields['sound_section']);
1192 }
1193
1194 $conversion_position['top'] = [
1195 'label' => __('Top', 'notificationx'),
1196 'value' => 'top',
1197 'rules' => Rules::is('source', $this->id),
1198 ];
1199 $conversion_position['bottom'] = [
1200 'label' => __('Bottom', 'notificationx'),
1201 'value' => 'bottom',
1202 'rules' => Rules::is('source', $this->id),
1203 ];
1204
1205 $_fields['sticky_bar'] = [
1206 'label' => __("Sticky Bar?", 'notificationx'),
1207 'name' => "sticky_bar",
1208 'type' => "checkbox",
1209 'default' => 0,
1210 'priority' => 60,
1211 'description' => __('If checked, this will fixed Notification Bar at top or bottom.', 'notificationx'),
1212 'rules' => Rules::is('source', $this->id),
1213 ];
1214
1215 $_fields['pressbar_body'] = [
1216 'label' => __("Display Overlapping", 'notificationx'),
1217 'name' => "pressbar_body",
1218 'type' => "checkbox",
1219 'default' => 0,
1220 'priority' => 61,
1221 'description' => __('Show Notification Bar overlapping content instead of pushing.', 'notificationx'),
1222 'rules' => Rules::is('source', $this->id),
1223 ];
1224
1225 //
1226 $fields["timing"]['fields']['delay_before'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['delay_before']);
1227 $fields["timing"]['fields']['display_for'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['display_for']);
1228 $fields["timing"]['fields']['delay_between'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['delay_between']);
1229
1230 $fields["timing"]['fields']['auto_hide'] = [
1231 'label' => __("Auto Hide", 'notificationx'),
1232 'name' => "auto_hide",
1233 'type' => "checkbox",
1234 'priority' => 50,
1235 'default' => false,
1236 'description' => __('If checked, notification bar will be hidden after the time set below.', 'notificationx'),
1237 'rules' => Rules::is('source', $this->id),
1238 ];
1239
1240 $fields["timing"]['fields']['hide_after'] = [
1241 'label' => __("Hide After", 'notificationx'),
1242 'name' => "hide_after",
1243 'type' => "number",
1244 'priority' => 55,
1245 'default' => 60,
1246 'description' => __('seconds', 'notificationx'),
1247 'help' => __('Hide after 60 seconds', 'notificationx'),
1248 'rules' => ['is', 'auto_hide', true],
1249 // 'rules' => Rules::is('source', $this->id),
1250 ];
1251 $fields["timing"]['fields']['appear_condition'] = [
1252 'label' => __('Notification Bar will Appear', 'notificationx'),
1253 'name' => 'appear_condition',
1254 'type' => 'radio-card',
1255 'priority' => 60,
1256 'classes' => 'radio-card-v2',
1257 'default' => 'delay',
1258 'options' => [
1259 'delay' => [
1260 'value' => 'after_few_seconds',
1261 'label' => __('After a few seconds', 'notificationx'),
1262 ],
1263 'scroll' => [
1264 'value' => 'on_scroll',
1265 'label' => __('On Scroll', 'notificationx'),
1266 ],
1267 ],
1268 'rules' => Rules::is('source', $this->id),
1269 ];
1270
1271 // This field appears only when "On Scroll" is selected
1272 $fields["timing"]['fields']['scroll_offset'] = [
1273 'label' => __('Scroll Offset', 'notificationx'),
1274 'name' => 'scroll_offset',
1275 'type' => 'group',
1276 'priority' => 65,
1277 'fields' => [
1278 'scroll_trigger_value' => [
1279 'name' => 'scroll_trigger_value',
1280 'type' => 'number',
1281 'min' => 0,
1282 'default' => 100,
1283 ],
1284 'scroll_trigger_mode' => [
1285 'type' => 'select',
1286 'name' => 'scroll_trigger_mode',
1287 'options' => GlobalFields::get_instance()->normalize_fields([
1288 'px' => __('PX', 'notificationx'),
1289 'vh' => __('VH', 'notificationx'),
1290 'percent' => __('%', 'notificationx'),
1291 ]),
1292 'default' => 'px',
1293 ],
1294 ],
1295 'rules' => ['is', 'appear_condition', 'on_scroll'],
1296 ];
1297
1298 $fields["timing"]['fields']['initial_delay'] = [
1299 'label' => __("Initial Delay", 'notificationx'),
1300 'name' => "initial_delay",
1301 'type' => "number",
1302 'priority' => 70,
1303 'default' => 5,
1304 'help' => __('Initial Delay', 'notificationx'),
1305 'description' => __('seconds', 'notificationx'),
1306 'rules' => Rules::logicalRule([
1307 Rules::is('source', $this->id),
1308 Rules::is('appear_condition', 'after_few_seconds'),
1309 ]),
1310 ];
1311
1312 $fields['targeting'] = [
1313 'label' => __('Targeting', 'notificationx'),
1314 'type' => 'section',
1315 'id' => 'targeting',
1316 'classes' => 'nx-targeting',
1317 'priority' => 100,
1318 'info' => InfoTooltipManager::get_instance()->render('button'),
1319 'fields' => []
1320 ];
1321
1322 // Country Targeting
1323 $fields['targeting']['fields']['country_targeting'] = [
1324 'label' => __('Country Targeting', 'notificationx'),
1325 'name' => 'country_targeting',
1326 'type' => 'better-select',
1327 'priority' => 10,
1328 'is_pro' => true,
1329 'multiple' => true,
1330 'values' => [ 'label' => "All Country", 'value' => 'all' ],
1331 'option' => GlobalFields::get_instance()->normalize_fields(Helper::nx_get_all_country()),
1332 'ajax' => [
1333 'api' => "/notificationx/v1/get-data",
1334 'data' => [
1335 'type' => "@type",
1336 'source' => "@source",
1337 // 'field' => "country_targeting",
1338 ],
1339 ],
1340 'rules' => Rules::is('source', $this->id),
1341 'info' => InfoTooltipManager::get_instance()->render('targeting'),
1342 ];
1343
1344 // User Role Targeting
1345 $wp_roles_with_default = [];
1346 if( is_array( $wp_roles ) ) {
1347 $wp_roles_with_default = array_merge(
1348 [ 'all_users' => __('Show for All Users', 'notificationx') ],
1349 $wp_roles
1350 );
1351 }
1352 $fields['targeting']['fields']['targeting_user_roles'] = [
1353 'label' => __('Set Target Audience', 'notificationx'),
1354 'name' => 'targeting_user_roles',
1355 'type' => 'select',
1356 'priority' => 20,
1357 'is_pro' => true,
1358 'default' => ['all_users'],
1359 'options' => GlobalFields::get_instance()->normalize_fields($wp_roles_with_default),
1360 'multiple' => true,
1361 'info' => InfoTooltipManager::get_instance()->render('targeting'),
1362 'rules' => Rules::is('source', $this->id),
1363 ];
1364
1365
1366 $fields["behaviour"]['fields']['display_last'] = Rules::is('source', $this->id, true, $fields["behaviour"]['fields']['display_last']);
1367 $fields["behaviour"]['fields']['display_from'] = Rules::is('source', $this->id, true, $fields["behaviour"]['fields']['display_from']);
1368 $fields["behaviour"]['fields']['loop'] = Rules::is('source', $this->id, true, $fields["behaviour"]['fields']['loop']);
1369 $fields["behaviour"] = Rules::logicalRule([
1370 Rules::logicalRule([
1371 Rules::isOfType('elementor_id', 'number', true),
1372 Rules::isOfType('gutenberg_id', 'number', true),
1373 ], 'and'),
1374 Rules::is('source', $this->id, true),
1375 ], 'or', $fields["behaviour"]);
1376 //Rules::isOfType('elementor_id', 'number', true, $fields["behaviour"]);
1377
1378 // Add Schedule section
1379 $_fields['schedule'] = array(
1380 'name' => 'schedule',
1381 'label' => __('Schedule', 'notificationx'),
1382 'type' => 'section',
1383 'is_pro' => true,
1384 'priority' => 96,
1385 'fields' => array(
1386 'schedule_type' => array(
1387 'name' => 'schedule_type',
1388 'type' => 'radio-card',
1389 'label' => __('Schedule Type', 'notificationx'),
1390 'priority' => 10,
1391 'classes' => 'radio-card-v2',
1392 'is_pro' => true,
1393 'default' => 'daily',
1394 'options' => array(
1395 'daily' => array(
1396 'value' => 'daily',
1397 'label' => __('Daily', 'notificationx'),
1398 // 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/schedule/daily.png',
1399 ),
1400 'weekly' => array(
1401 'value' => 'weekly',
1402 'label' => __('Weekly', 'notificationx'),
1403 // 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/schedule/weekly.png',
1404 ),
1405 'custom' => array(
1406 'value' => 'custom',
1407 'label' => __('Custom', 'notificationx'),
1408 // 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/schedule/custom.png',
1409 ),
1410 ),
1411 'info' => InfoTooltipManager::get_instance()->render('schedule_type'),
1412 ),
1413 'daily_from_time' => array(
1414 'name' => 'daily_from_time',
1415 'type' => 'timepicker',
1416 'label' => __('From', 'notificationx'),
1417 'priority' => 20,
1418 'is_pro' => true,
1419 'format' => 'h:i A',
1420 'rules' => Rules::is('schedule_type', 'daily'),
1421 ),
1422 'daily_to_time' => array(
1423 'name' => 'daily_to_time',
1424 'type' => 'timepicker',
1425 'label' => __('To', 'notificationx'),
1426 'priority' => 30,
1427 'is_pro' => true,
1428 'format' => 'h:i A',
1429 'rules' => Rules::is('schedule_type', 'daily'),
1430 ),
1431 'weekly_days' => array(
1432 'name' => 'weekly_days',
1433 'type' => 'select',
1434 'label' => __('Select Days', 'notificationx'),
1435 'priority' => 40,
1436 'is_pro' => true,
1437 'multiple' => true,
1438 'options' => GlobalFields::get_instance()->normalize_fields([
1439 'monday' => __('Monday', 'notificationx'),
1440 'tuesday' => __('Tuesday', 'notificationx'),
1441 'wednesday' => __('Wednesday', 'notificationx'),
1442 'thursday' => __('Thursday', 'notificationx'),
1443 'friday' => __('Friday', 'notificationx'),
1444 'saturday' => __('Saturday', 'notificationx'),
1445 'sunday' => __('Sunday', 'notificationx'),
1446 ]),
1447 'info' => InfoTooltipManager::get_instance()->render('advanced_template'),
1448 'rules' => Rules::is('schedule_type', 'weekly'),
1449 ),
1450 'weekly_from_time' => array(
1451 'name' => 'weekly_from_time',
1452 'type' => 'timepicker',
1453 'label' => __('From', 'notificationx'),
1454 'priority' => 50,
1455 'is_pro' => true,
1456 'format' => 'h:i A',
1457 'rules' => Rules::is('schedule_type', 'weekly'),
1458 ),
1459 'weekly_to_time' => array(
1460 'name' => 'weekly_to_time',
1461 'type' => 'timepicker',
1462 'label' => __('To', 'notificationx'),
1463 'priority' => 60,
1464 'format' => 'h:i A',
1465 'is_pro' => true,
1466 'rules' => Rules::is('schedule_type', 'weekly'),
1467 ),
1468 'custom_schedule' => array(
1469 'name' => 'custom_schedule',
1470 'type' => 'daterange',
1471 'label' => __('Custom Schedule', 'notificationx'),
1472 'priority' => 65,
1473 'is_pro' => true,
1474 'format' => 'h:i A',
1475 'info' => InfoTooltipManager::get_instance()->render('advanced_template'),
1476 'rules' => Rules::is('schedule_type', 'custom'),
1477 ),
1478 'custom_from_time' => array(
1479 'name' => 'custom_from_time',
1480 'type' => 'timepicker',
1481 'label' => __('From', 'notificationx'),
1482 'priority' => 70,
1483 'is_pro' => true,
1484 'format' => 'h:i A',
1485 'rules' => Rules::is('schedule_type', 'custom'),
1486 ),
1487 'custom_to_time' => array(
1488 'name' => 'custom_to_time',
1489 'type' => 'timepicker',
1490 'label' => __('To', 'notificationx'),
1491 'priority' => 75,
1492 'is_pro' => true,
1493 'format' => 'h:i A',
1494 'rules' => Rules::is('schedule_type', 'custom'),
1495 ),
1496 ),
1497 'rules' => Rules::logicalRule([
1498 Rules::is('source', $this->id),
1499 ]),
1500 );
1501
1502 return $fields;
1503 }
1504
1505 /**
1506 * This method is an implementable method for All Extension coming forward.
1507 *
1508 * @param array $args Settings arguments.
1509 * @return mixed
1510 */
1511 // public function source_fields($fields) {
1512 // $conversion_position = &$fields["source_tab"]['fields']['source'];
1513 // $conversion_position['condition']['type'] = '!press_bar';
1514 // return $fields;
1515 // }
1516
1517 public function before_delete_post($postid) {
1518 $post_meta = get_post_meta($postid, '_nx_bar_elementor_type_id', true);
1519 $this->nx_elementor_id = [
1520 'post_meta' => $post_meta,
1521 'postid' => $postid,
1522 ];
1523 }
1524
1525 public function nx_delete_post($postid, $post) {
1526 $elementor_id = isset($post['elementor_id']) ? $post['elementor_id'] : false;
1527 $gutenberg_id = isset($post['gutenberg_id']) ? $post['gutenberg_id'] : false;
1528
1529 $this->delete_elementor_post($elementor_id);
1530 $this->gutenberg_remove($gutenberg_id);
1531 }
1532
1533 public function delete_elementor_post($elementor_id) {
1534 if(!empty($elementor_id)){
1535 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
1536 $languages = apply_filters( 'wpml_active_languages', NULL );
1537 if(is_array($languages)){
1538 foreach ($languages as $lang => $val) {
1539 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
1540 $elementor_post_id = apply_filters( 'wpml_object_id', $elementor_id, 'nx_bar', false, $lang);
1541 if($elementor_post_id){
1542 wp_delete_post($elementor_post_id, true);
1543 }
1544 }
1545 return;
1546 }
1547 wp_delete_post($elementor_id, true);
1548 }
1549 }
1550
1551 /**
1552 * Register Post Type for NotificationX Bar.
1553 *
1554 * @return void
1555 */
1556 public static function register_post_type() {
1557 // var_dump(current_action());die;
1558 $args = [
1559 'label' => __('NotificationX Bar', 'notificationx'),
1560 'public' => false,
1561 'publicly_queryable' => true,
1562 'show_ui' => false,
1563 'rewrite' => false,
1564 'menu_icon' => 'dashicons-admin-page',
1565 'show_in_menu' => true,
1566 'show_in_nav_menus' => false,
1567 'exclude_from_search' => true,
1568 'capability_type' => 'post',
1569 'hierarchical' => false,
1570 'supports' => ['title', 'content', 'author', 'elementor'],
1571 ];
1572 register_post_type('nx_bar', $args);
1573
1574 // $args = [
1575 // 'label' => __('NotificationX Bar', 'notificationx'),
1576 // 'public' => true,
1577 // 'show_ui' => true,
1578 // 'rewrite' => false,
1579 // 'menu_icon' => 'dashicons-admin-page',
1580 // 'show_in_menu' => true,
1581 // 'show_in_nav_menus' => false,
1582 // // 'show_in_rest' => false,
1583 // 'exclude_from_search' => true,
1584 // 'capability_type' => 'post',
1585 // 'hierarchical' => false,
1586 // 'supports' => ['title', 'content', 'author'],
1587 // ];
1588 // register_post_type('nx_bar_eb', $args);
1589
1590 register_post_type(
1591 'nx_bar_eb',
1592 array(
1593 'label' => __('NotificationX Bar (Gutenberg)', 'notificationx'),
1594 'show_in_rest' => true,
1595 'public' => false,
1596 'publicly_queryable' => true,
1597 'exclude_from_search'=> true,
1598 'show_ui' => true,
1599 'can_export' => true,
1600 'show_in_menu' => false,
1601 'show_in_nav_menus' => false,
1602 'rewrite' => false,
1603 // 'publicly_queryable' => false,
1604 'template_lock' => 'block',
1605 'rest_base' => 'NotificationX',
1606 'capability_type' => 'block',
1607 'rest_controller_class' => 'WP_REST_Blocks_Controller',
1608 'capabilities' => array(
1609 // You need to be able to edit posts, in order to read blocks in their raw form.
1610 'read' => 'edit_posts',
1611 // You need to be able to publish posts, in order to create blocks.
1612 'create_posts' => 'publish_posts',
1613 'edit_posts' => 'edit_posts',
1614 'edit_published_posts' => 'edit_published_posts',
1615 'delete_published_posts' => 'delete_published_posts',
1616 // Enables trashing draft posts as well.
1617 'delete_posts' => 'delete_posts',
1618 'edit_others_posts' => 'edit_others_posts',
1619 'delete_others_posts' => 'delete_others_posts',
1620 ),
1621 'map_meta_cap' => true,
1622 'supports' => array(
1623 'title',
1624 'editor',
1625 'revisions',
1626 'custom-fields',
1627 ),
1628 )
1629 );
1630 }
1631
1632 public function convert_to_php_array($array) {
1633 $new_array = [];
1634 foreach ($array as $arr) {
1635 preg_match('/(.*)[\[](.*)[\]]/', $arr['name'], $matches);
1636 if (!empty($matches) && is_array($matches)) {
1637 $new_array[$matches[1]][$matches[2]] = $arr['value'];
1638 } else {
1639 $new_array[$arr['name']] = $arr['value'];
1640 }
1641 }
1642 return $new_array;
1643 }
1644
1645 /**
1646 * This methods is responsible for creating nx_bar post
1647 * to enable elementor to design the bar for you.
1648 *
1649 * @return void
1650 */
1651 public function create_bar_of_type_bar_with_elementor($params) {
1652 if (!isset($params['theme_id'])) {
1653 return;
1654 }
1655
1656 $theme = sanitize_text_field($params['theme_id']);
1657
1658
1659 $importer = new Importer();
1660
1661 $ID = $importer->create_nx([
1662 'theme' => $theme,
1663 'post_title' => 'Design for NotificationX Bar - ',
1664 ]);
1665
1666 if ($ID && !is_wp_error($ID)) {
1667 update_post_meta($ID, '_wp_page_template', 'elementor_canvas');
1668 wp_send_json_success(array(
1669 'context' => [
1670 'themes' => null,
1671 'elementor_id' => $ID,
1672 'elementor_edit_link' => \Elementor\Plugin::$instance->documents->get($ID)->get_edit_url(),
1673 // 'bar_edit_link' => get_edit_post_link($ID, 'internal'),
1674 // 'visit' => get_permalink($ID),
1675 ]
1676 ));
1677 } else {
1678 wp_send_json_error('failed');
1679 }
1680 }
1681
1682
1683 /**
1684 * Undocumented function
1685 *
1686 * @param array $options
1687 * @return array
1688 */
1689 public function content_fields($fields) {
1690
1691 $fields['content']['fields']['press_sliding_text'] = array(
1692 'name' => 'sliding_text',
1693 'label' => __('Text Content', 'notificationx'),
1694 'type' => 'section',
1695 'classes' => NotificationX::is_pro() ? 'pro-activated' : 'pro-deactivated',
1696 'priority' => 51,
1697 'fields' => array(
1698 'bar_content_type' => array(
1699 'name' => 'bar_content_type',
1700 'type' => 'radio-card',
1701 'label' => __('Content', 'notificationx'),
1702 'priority' => 5,
1703 'classes' => 'radio-card-v2',
1704 'default' => 'static',
1705 'options' => array(
1706 'static' => array(
1707 'label' => __('Static Text', 'notificationx'),
1708 'value' => 'static',
1709 // 'icon' => 'dashicons-align-left',
1710 ),
1711 'sliding' => array(
1712 'label' => __('Slide Multiple Text', 'notificationx'),
1713 'value' => 'sliding',
1714 'is_pro' => true,
1715 // 'icon' => 'dashicons-align-right',
1716 ),
1717 ),
1718 ),
1719 'press_content' => array(
1720 'name' => 'press_content',
1721 'type' => 'nx-editor',
1722 'label' => __('Static Text', 'notificationx'),
1723 'placeholder' => __('Write something here...', 'notificationx'),
1724 'priority' => 7,
1725 'rules' => Rules::logicalRule([
1726 Rules::is('bar_content_type', 'static'),
1727 Rules::is('source', $this->id),
1728 ]),
1729 ),
1730 'sliding_content' => array(
1731 'name' => 'sliding_content',
1732 'type' => 'simple-repeater',
1733 'label' => __('Sliding Text Items', 'notificationx'),
1734 'priority' => 10,
1735 'button' => array(
1736 'label' => __('Add New', 'notificationx'),
1737 ),
1738 '_default' => array(
1739 array(
1740 'title' => __('🚀 Supercharge Your Marketing Forever!', 'notificationx'),
1741 ),
1742 array(
1743 'title' => __('Get <strong>Lifetime Access to NotificationX</strong> for just <strong>$299</strong>', 'notificationx'),
1744 ),
1745 ),
1746 '_fields' => array(
1747 array(
1748 'name' => 'title',
1749 'type' => 'editor',
1750 'label' => __('Slide Text', 'notificationx'),
1751 'priority' => 10,
1752 ),
1753 ),
1754 'rules' => Rules::logicalRule([
1755 Rules::is('bar_content_type', 'sliding'),
1756 Rules::is('source', $this->id),
1757 ]),
1758 ),
1759 'sliding_interval' => array(
1760 'name' => 'sliding_interval',
1761 'type' => 'number',
1762 'label' => __('Sliding Interval', 'notificationx'),
1763 'priority' => 20,
1764 'default' => 3000,
1765 'description' => 'ms',
1766 'help' => __('Time interval between slides in milliseconds', 'notificationx'),
1767 'rules' => Rules::logicalRule([
1768 Rules::is('bar_content_type', 'sliding'),
1769 Rules::is('source', $this->id),
1770 ]),
1771 ),
1772 ),
1773 'rules' => Rules::logicalRule([
1774 Rules::is('source', $this->id),
1775 ]),
1776 );
1777
1778 $fields['content']['fields']['button_text'] = array(
1779 'name' => 'button_text',
1780 'type' => 'text',
1781 'label' => __('Button Text', 'notificationx'),
1782 'priority' => 60,
1783 'default' => __('Get Offer', 'notificationx'),
1784 'rules' => Rules::logicalRule([
1785 // Rules::isOfType('elementor_id', 'number', true),
1786 Rules::is('source', $this->id),
1787 ]),
1788 );
1789 $fields['content']['fields']['button_url'] = array(
1790 'name' => 'button_url',
1791 'type' => 'text',
1792 'label' => __('Button URL', 'notificationx'),
1793 'default' => '#',
1794 'priority' => 70,
1795 'rules' => Rules::logicalRule([
1796 // Rules::isOfType('elementor_id', 'number', true),
1797 Rules::is('source', $this->id),
1798 ]),
1799 );
1800 $fields['content']['fields']['button_icon'] = array(
1801 'name' => 'button_icon',
1802 'type' => 'icon-picker',
1803 'label' => __('Button Icon', 'notificationx'),
1804 'priority' => 75,
1805 'iconPrefix' => NOTIFICATIONX_ADMIN_URL . 'images/icons/',
1806 'options' => [
1807 [
1808 'icon' => 'shop_now.svg',
1809 'label' => __('Shop Now', 'notificationx')
1810 ],
1811 [
1812 'icon' => 'shop_now_white.svg',
1813 'label' => __('Shop Now White ', 'notificationx')
1814 ],
1815 ],
1816 'description' => __('Select an icon to display before the button text', 'notificationx'),
1817 'rules' => Rules::logicalRule([
1818 // Rules::isOfType('elementor_id', 'number', true),
1819 Rules::is('source', $this->id),
1820 ]),
1821 );
1822 $fields['content']['fields']['bar_transition_speed'] = [
1823 'label' => __('Transition Speed', 'notificationx'),
1824 'name' => "bar_transition_speed",
1825 'type' => "number",
1826 'default' => '500',
1827 'description' => 'ms',
1828 'priority' => 100,
1829 'help' => __('Transition speed in milliseconds', 'notificationx'),
1830 'rules' => Rules::logicalRule([
1831 Rules::is('bar_content_type', 'sliding'),
1832 Rules::is('source', $this->id),
1833 ]),
1834 ];
1835 $fields['content']['fields']['bar_transition_style'] = [
1836 'label' => __('Transition Style', 'notificationx'),
1837 'name' => "bar_transition_style",
1838 'type' => "select",
1839 'priority' => 110,
1840 'default' => 'slide_right',
1841 'options' => GlobalFields::get_instance()->normalize_fields([
1842 'slide_right' => __('Slide in Right', 'notificationx'),
1843 'slide_left' => __('Slide in Left', 'notificationx'),
1844 ]),
1845 'rules' => Rules::logicalRule([
1846 Rules::is('bar_content_type', 'sliding'),
1847 Rules::is('source', $this->id),
1848 ]),
1849 ];
1850
1851 $fields['bar_coupon'] = array(
1852 'name' => 'bar_coupon',
1853 'label' => __('Coupon', 'notificationx'),
1854 'type' => 'section',
1855 'priority' => 94,
1856 'dependency_class' => [
1857 'name' => 'enable_coupon',
1858 'is' => true,
1859 'classes' => 'coupon_active',
1860 'selector' => '#bar_coupon',
1861 ],
1862 'fields' => array(
1863 'enable_coupon' => array(
1864 'name' => 'enable_coupon',
1865 'label' => __('Enable Coupon', 'notificationx'),
1866 'type' => 'toggle',
1867 'default' => false,
1868 ),
1869 'coupon_text' => array(
1870 'name' => 'coupon_text',
1871 'label' => __('Button Text', 'notificationx'),
1872 'type' => 'text',
1873 'default' => __('SAVE20', 'notificationx'),
1874 'priority' => 10,
1875 'rules' => Rules::logicalRule([
1876 Rules::is('enable_coupon', true),
1877 ]),
1878 ),
1879 'coupon_code' => array(
1880 'name' => 'coupon_code',
1881 'label' => __('Coupon Code', 'notificationx'),
1882 'type' => 'text',
1883 'default' => __('SAVE20', 'notificationx'),
1884 'priority' => 12,
1885 'rules' => Rules::logicalRule([
1886 Rules::is('enable_coupon', true),
1887 ]),
1888 ),
1889 'coupon_copied_text' => array(
1890 'name' => 'coupon_copied_text',
1891 'label' => __('Coupon Copied Text', 'notificationx'),
1892 'type' => 'text',
1893 'default' => __('Copied!', 'notificationx'),
1894 'priority' => 20,
1895 'rules' => Rules::logicalRule([
1896 Rules::is('enable_coupon', true),
1897 ]),
1898 ),
1899 'coupon_tooltip' => array(
1900 'name' => 'coupon_tooltip',
1901 'label' => __('Coupon Tooltip', 'notificationx'),
1902 'type' => 'textarea',
1903 'default' => __('Use this coupon code to get 20% off', 'notificationx'),
1904 'priority' => 30,
1905 'rules' => Rules::logicalRule([
1906 Rules::is('enable_coupon', true),
1907 ]),
1908 ),
1909 'coupon_bg_color' => array(
1910 'name' => 'coupon_bg_color',
1911 'label' => __('Coupon Background Color', 'notificationx'),
1912 'type' => 'colorpicker',
1913 'default' => '#ffffff',
1914 'priority' => 40,
1915 'rules' => Rules::logicalRule([
1916 Rules::is('enable_coupon', true),
1917 ]),
1918 ),
1919 'coupon_text_color' => array(
1920 'name' => 'coupon_text_color',
1921 'label' => __('Coupon Text Color', 'notificationx'),
1922 'type' => 'colorpicker',
1923 'default' => '#000000',
1924 'priority' => 50,
1925 'rules' => Rules::logicalRule([
1926 Rules::is('enable_coupon', true),
1927 ]),
1928 ),
1929 'coupon_border_color' => array(
1930 'name' => 'coupon_border_color',
1931 'label' => __('Coupon Border Color', 'notificationx'),
1932 'type' => 'colorpicker',
1933 'default' => '#dddddd',
1934 'priority' => 60,
1935 'rules' => Rules::logicalRule([
1936 Rules::is('enable_coupon', true),
1937 ]),
1938 ),
1939 ),
1940 'rules' => Rules::logicalRule([
1941 Rules::is('source', $this->id),
1942 ]),
1943 );
1944
1945 $fields['countdown_timer'] = array(
1946 'name' => 'countdown_timer',
1947 'label' => __('Countdown Timer', 'notificationx'),
1948 'type' => 'section',
1949 'priority' => 95,
1950 'fields' => array(
1951 'enable_countdown' => array(
1952 'name' => 'enable_countdown',
1953 'label' => __('Enable Countdown', 'notificationx'),
1954 'type' => 'checkbox',
1955 // 'default' => true,
1956 ),
1957 'evergreen_timer' => array(
1958 'name' => 'evergreen_timer',
1959 'label' => __('Evergreen Timer', 'notificationx'),
1960 'type' => 'checkbox',
1961 'is_pro' => true,
1962 'switch' => true,
1963 'description' => sprintf('%s, <a target="_blank" href="%s">%s</a>', __('To configure Evergreen Timer', 'notificationx'), 'https://notificationx.com/docs/evergreen-timer/', 'check out this doc'),
1964 'rules' => ['is', 'enable_countdown', true],
1965 ),
1966 'countdown_text' => array(
1967 'name' => 'countdown_text',
1968 'label' => __('Countdown Text', 'notificationx'),
1969 'type' => 'text',
1970 'default' => __('Ending in', 'notificationx'),
1971 'rules' => Rules::logicalRule([
1972 // Rules::is('elementor_id', false),
1973 // Rules::is('gutenberg_id', false),
1974 Rules::is('enable_countdown', true),
1975 ]),
1976 ),
1977 'countdown_expired_text' => array(
1978 'name' => 'countdown_expired_text',
1979 'label' => __('Expired Text', 'notificationx'),
1980 'type' => 'text',
1981 'default' => __('Expired', 'notificationx'),
1982 'rules' => Rules::logicalRule([
1983 Rules::is('elementor_id', false),
1984 Rules::is('gutenberg_id', false),
1985 Rules::is('evergreen_timer', false),
1986 Rules::is('enable_countdown', true),
1987 ]),
1988 ),
1989 'countdown_start_date' => array(
1990 'name' => 'countdown_start_date',
1991 'label' => __('Start Date', 'notificationx'),
1992 'type' => 'date',
1993 // 'default' => date('Y-m-d H:i:s', time()),
1994 'rules' => ["and", ['is', 'evergreen_timer', false], ['is', 'enable_countdown', true]],
1995 ),
1996 'countdown_end_date' => array(
1997 'name' => 'countdown_end_date',
1998 'label' => __('End Date', 'notificationx'),
1999 'type' => 'date',
2000 // @todo Something
2001 'default' => gmdate('Y-m-d H:i:s', time() + 7 * 24 * 60 * 60),
2002 'rules' => ["and", ['is', 'evergreen_timer', false], ['is', 'enable_countdown', true]],
2003 ),
2004 'time_randomize' => array(
2005 'name' => 'time_randomize',
2006 'label' => __('Randomize', 'notificationx'),
2007 'type' => 'checkbox',
2008 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true]],
2009 ),
2010 'time_randomize_between' => array(
2011 'name' => 'time_randomize_between',
2012 'label' => __('Time Between', 'notificationx'),
2013 'type' => 'group',
2014 'fields' => [
2015 'start_time' => array(
2016 'name' => 'start_time',
2017 'type' => 'number',
2018 'label' => __('Start Time', 'notificationx'),
2019 'priority' => 0,
2020 'default' => 6,
2021 ),
2022 'end_time' => array(
2023 'name' => 'end_time',
2024 'type' => 'number',
2025 'label' => __('End Time', 'notificationx'),
2026 'priority' => 1,
2027 'default' => 12,
2028 ),
2029 ],
2030 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true], ['is', 'time_randomize', true]],
2031 ),
2032 'time_rotation' => array(
2033 'name' => 'time_rotation',
2034 'label' => __('Time Rotation', 'notificationx'),
2035 'type' => 'number',
2036 'description' => 'hours',
2037 'default' => 315,
2038 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true], ['is', 'time_randomize', false]]
2039 ),
2040 'time_reset' => array(
2041 'name' => 'time_reset',
2042 'label' => __('Daily Time Reset', 'notificationx'),
2043 'type' => 'checkbox',
2044 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true]],
2045 ),
2046 'close_forever' => array(
2047 'name' => 'close_forever',
2048 'label' => __('Permanent Close', 'notificationx'),
2049 'type' => 'checkbox',
2050 ),
2051 'close_after_expire' => array(
2052 'name' => 'close_after_expire',
2053 'label' => __('Close After Expire', 'notificationx'),
2054 'type' => 'checkbox',
2055 ),
2056 ),
2057 'rules' => Rules::logicalRule([
2058 Rules::is('source', $this->id),
2059 ]),
2060 );
2061
2062 $fields["content"]['fields']['template_adv'] = Rules::is('source', $this->id, true, $fields["content"]['fields']['template_adv']);
2063 $fields["content"]['fields']['advanced_template'] = Rules::is('source', $this->id, true, $fields["content"]['fields']['advanced_template']);
2064 $fields["content"] = Rules::logicalRule([
2065 Rules::logicalRule([
2066 Rules::isOfType('elementor_id', 'number', true),
2067 Rules::isOfType('gutenberg_id', 'number', true),
2068 ], 'and'),
2069 Rules::is('source', $this->id, true),
2070 ], 'or', $fields["content"]);
2071
2072 $fields['content']['fields']['random_order'] = Rules::is('source', $this->id, true, $fields["content"]['fields']['random_order']);
2073
2074 return $fields;
2075 }
2076
2077 public function print_bar_notice($settings, $is_shortcode = false) {
2078 $settings = new GetData($settings, \ArrayObject::ARRAY_AS_PROPS);
2079 $elementor_post_id = isset($settings->elementor_id) ? $settings->elementor_id : '';
2080 $gb_post_id = isset($settings->gutenberg_id) ? $settings->gutenberg_id : '';
2081
2082 if ($elementor_post_id != '' && get_post_status($elementor_post_id) === 'publish' && class_exists('\Elementor\Plugin')) {
2083 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
2084 $elementor_post_id = apply_filters( 'wpml_object_id', $elementor_post_id, 'nx_bar', true);
2085 return \Elementor\Plugin::$instance->frontend->get_builder_content_for_display($elementor_post_id, false);
2086 } else if (!empty($gb_post_id)) {
2087 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
2088 $gb_post_id = apply_filters( 'wpml_object_id', $gb_post_id, 'wp_block', true);
2089 $post = get_post($gb_post_id);
2090 $content = $post->post_content;
2091 $content = do_blocks($content);
2092
2093 return $content;
2094 } else {
2095 return !empty($settings->press_content) ? do_shortcode($settings->press_content) : '';
2096 }
2097 }
2098
2099 public function add_scripts($settings, $params){
2100 if(!empty($settings['gutenberg_id'])){
2101 $settings['gutenberg_url'] = get_permalink($settings['gutenberg_id']);
2102 }
2103 return $settings;
2104 }
2105
2106 public function hide_image_field($fields) {
2107 $fields['image-section'] = Rules::is('source', $this->id, true, $fields['image-section']);
2108 return $fields;
2109 }
2110
2111 public function nx_get_post($post) {
2112 if (isset($post['source']) && $post['source'] == $this->id && !empty($post['elementor_id']) && class_exists('\Elementor\Plugin')) {
2113 try {
2114 $document = \Elementor\Plugin::$instance->documents->get($post['elementor_id']);
2115 if(!empty($document)){
2116 $post['elementor_edit_link'] = $document->get_edit_url();
2117 $bar_post = $document->get_post();
2118 if(!empty($bar_post->post_title)){
2119 foreach ($this->bar_themes as $key => $theme) {
2120 if(strpos($bar_post->post_title, $theme['title']) !== false){
2121 $post['elementor_bar_theme'] = $theme['value'];
2122 unset($post['theme']);
2123 unset($post['themes']);
2124 break;
2125 }
2126 }
2127 }
2128 }
2129 else{
2130 unset($post['elementor_id']);
2131 }
2132 } finally {
2133 }
2134 }
2135 return $post;
2136 }
2137
2138 public function gutenberg_import($params) {
2139 // Get the JSON file content
2140 $json_file = file_get_contents(__DIR__ . "/jsons-gb/" . $params['theme_id'] . '.json');
2141
2142 // Decode the JSON content into an array
2143 $pattern_data = json_decode($json_file, true);
2144
2145 // Get the sync status from the pattern data
2146 $sync_status = $pattern_data['syncStatus'];
2147
2148 // Create an array of arguments for the wp_block post
2149 $post_args = array(
2150 'post_title' => $pattern_data['title'], // use the pattern title as the post title
2151 'post_content' => $pattern_data['content'], // use the pattern content as the post content
2152 'post_status' => 'publish', // set the post status to publish
2153 'post_type' => 'nx_bar_eb', // set the post type to wp_block
2154 );
2155
2156 // Insert the wp_block post
2157 $post_id = wp_insert_post($post_args);
2158
2159
2160 // Check for errors
2161 if ($post_id && !is_wp_error($post_id)) {
2162 // Display the error message
2163 if (!empty($sync_status)) {
2164 update_post_meta($post_id, 'wp_pattern_sync_status', $sync_status);
2165 }
2166 // Display a success message
2167 return [
2168 'success' => true,
2169 'data' => [
2170 'context' => [
2171 'themes' => null,
2172 'gutenberg_id' => $post_id,
2173 'gutenberg_edit_link' => get_edit_post_link($post_id, 'link'),
2174 ],
2175 ],
2176 ];
2177 } else {
2178 return [
2179 'success' => true,
2180 'data' => 'failed',
2181 ];
2182 }
2183 }
2184
2185 public function gutenberg_remove($pid){
2186 if(!empty($pid)){
2187 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
2188 $languages = apply_filters( 'wpml_active_languages', NULL );
2189 if(is_array($languages)){
2190 foreach ($languages as $lang => $val) {
2191 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
2192 $wpml_pid = apply_filters( 'wpml_object_id', $pid, 'wp_block', false, $lang);
2193 if($wpml_pid){
2194 wp_delete_post($wpml_pid, true);
2195 }
2196 }
2197 return;
2198 }
2199 wp_delete_post($pid, true);
2200 }
2201 }
2202
2203 public function templately_cloud_push_post_type($post_type){
2204
2205 if($post_type == 'nx_bar_eb'){
2206 $post_type = 'NX Bar';
2207 }
2208 return $post_type;
2209 }
2210
2211 public function preview_settings($settings){
2212 if(!empty($settings['gutenberg_id'])){
2213 $settings['gutenberg_url'] = get_permalink($settings['gutenberg_id']);
2214 }
2215 return $settings;
2216 }
2217
2218 /**
2219 *
2220 * https://docs.wp-rocket.me/article/1529-remove-unused-css
2221 *
2222 * @param array $list
2223 * @return array
2224 */
2225 public function rocket_rucss_safelist($list){
2226 try {
2227 $posts = PostType::get_instance()->get_posts(['source' => $this->id]);
2228 foreach ($posts as $post) {
2229 if(class_exists('Elementor\Core\Files\CSS\Post') && !empty($post['elementor_id'])){
2230 $css = Post_CSS::create( $post['elementor_id'] );
2231 if(!empty($css)){
2232 // maybe need to remove the domain from url
2233 $list[] = $css->get_url();
2234 }
2235 }
2236 }
2237 } catch (\Exception $th) {
2238 //throw $th;
2239 }
2240 return $list;
2241 }
2242
2243 /**
2244 * Load plugin dependencies.
2245 * @return void
2246 */
2247 public function load_plugin_dependencies() {
2248 if(!Helper::is_plugin_active('essential-blocks/essential-blocks.php')){
2249 $this->popup = array(
2250 // forcing the popup without the is_pro.
2251 "forced" => true,
2252 "showConfirmButton" => true,
2253 "showCloseButton" => true,
2254 "title" => "You are missing a dependency.",
2255 "customClass" => array(
2256 "container" => "pressbar-gutenberg-theme-popup",
2257 // "closeButton" => "pro-video-close-button",
2258 // "icon" => "pro-video-icon",
2259 // "title" => "pro-video-title",
2260 // "content" => "pro-video-content",
2261 // "actions" => "nx-pro-alert-actions",
2262 // "confirmButton" => "pro-video-confirm-button",
2263 // "denyButton" => "pro-video-deny-button"
2264 ),
2265 "denyButtonText" => sprintf("<a href='%s' target='_blank'>%s</a>", admin_url('plugin-install.php?s=Essential%2520Blocks&tab=search&type=term'), __("Install Essential Blocks", 'notificationx')),
2266 "confirmButtonText" => "<a href='https://essential-blocks.com/' target='_blank'>More Info</a>",
2267 "html" => "
2268 <span>Highlight your sales, low stock updates with inline growth alert to boost sales</span>
2269 "
2270 );
2271 }
2272 }
2273
2274 public function doc() {
2275 /* translators: %1$s: Elementor documentation URL, %2$s: Gutenberg documentation URL, %3$s: documentation URL, %4$s: blog post URL, %5$s: blog post URL */
2276 return sprintf(__('<p>Supercharge your WordPress site with an <strong>AI-powered Notification Bar</strong> that help you create and launches instant popup campaigns — smarter and faster than ever. Let AI generate compelling bar content for you in seconds. Need help getting started? Explore our step-by-step guides to set up your AI-enhanced notification bars using both <a target="_blank" href="%1$s">Elementor</a> and <a target="_blank" href="%2$s">Gutenberg</a>.</p>
2277 <p>🎦 Check the <a target = "_blank" href = "%3$s">documentation</a> for a quick guide.</p>
2278 <p><strong>Recommended Blog : </strong></p>
2279 <p>🔥<a target="_blank" href="%4$s">How to Design a Notification Bar with AI Using NotificationX (A Comprehensive Guide)</a></p>
2280 <p>🔥 <a href="%5$s" target="_blank">How to design a Notification Bar with Elementor Page Builder.</p>', 'notificationx'),
2281 'https://notificationx.com/docs/notification-bar/',
2282 'https://notificationx.com/docs/configure-a-notification-bar-in-gutenberg/',
2283 'https://notificationx.com/docs/how-to-design-a-notification-bar-with-ai/',
2284 'https://notificationx.com/blog/guide-to-design-a-notification-bar-with-ai/',
2285 'https://notificationx.com/docs/notification-bar-with-elementor/'
2286 );
2287 }
2288 }
2289