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 / Admin / Admin.php

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

505 lines 18.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class File.
4 *
5 * @package NotificationX\Admin
6 */
7
8 namespace NotificationX\Admin;
9
10 use NotificationX\Admin\Rating\RatingEmail;
11 use NotificationX\NotificationX;
12 use NotificationX\Admin\Reports\ReportEmail;
13 use NotificationX\Admin\Scanner\Scanner;
14 use NotificationX\Core\Analytics;
15 use NotificationX\Core\Dashboard;
16 use NotificationX\Core\Database;
17 use NotificationX\Core\PostType;
18 use NotificationX\Core\SetupWizard;
19 use NotificationX\Core\Upgrader;
20 use NotificationX\GetInstance;
21 use NotificationX\Extensions\ExtensionFactory;
22
23 use PriyoMukul\WPNotice\Notices;
24 use PriyoMukul\WPNotice\Utils\CacheBank;
25 use PriyoMukul\WPNotice\Utils\NoticeRemover;
26
27 /**
28 * Admin Class, this class is responsible for all Admin Actions
29 * @method static Admin get_instance($args = null)
30 */
31 class Admin {
32 /**
33 * Instance of Admin
34 *
35 * @var Admin
36 */
37 use GetInstance;
38 /**
39 * Assets Path and URL
40 */
41 const ASSET_URL = NOTIFICATIONX_ASSETS . 'admin/';
42 const ASSET_PATH = NOTIFICATIONX_ASSETS_PATH . 'admin/';
43 const VIEWS_PATH = NOTIFICATIONX_INCLUDES . 'Admin/views/';
44
45 private $insights = null;
46
47 /**
48 * @var CacheBank
49 */
50 private static $cache_bank;
51
52 /**
53 * Initially Invoked
54 * when its initialized.
55 */
56 public function __construct(){
57 /**
58 * Admin Dashboard Widget
59 * For Analytics
60 */
61 Analytics::get_instance();
62 ReportEmail::get_instance();
63 RatingEmail::get_instance();
64 ImportExport::get_instance();
65 XSS::get_instance();
66 InfoTooltipManager::get_instance();
67 add_action('init', [$this, 'init'], 5);
68 add_filter('nx_rest_miscellaneous', [$this, 'handle_miscellaneous_actions'], 10, 2);
69 add_filter('nx_builder_configs', [$this, 'add_popup_status_to_context'], 10, 1);
70 }
71
72 /**
73 * This method is reponsible for Admin Menu of
74 * NotificationX
75 *
76 * @return void
77 */
78 public function init(){
79 if( ! NotificationX::is_pro() ){
80 $this->plugin_usage_insights();
81 $this->admin_notices();
82 $is_embedpress_milestone_showing = get_option('is_embedpress_milestone_showing', false);
83 if (!$is_embedpress_milestone_showing) {
84 MilestoneNotification::get_instance();
85 }
86 }
87 add_action('admin_init', [$this, 'admin_init']);
88 add_action('admin_menu', [$this, 'menu'], 10);
89 Dashboard::get_instance();
90 SetupWizard::get_instance();
91 PostType::get_instance();
92 Settings::get_instance()->init();
93 Entries::get_instance();
94 Scanner::get_instance();
95 }
96
97 /**
98 * This method is responsible for Admin Menu of
99 * NotificationX
100 *
101 * @return void
102 */
103 public function admin_init(){
104 DashboardWidget::get_instance();
105 add_action('in_admin_header', [ $this, 'hide_others_plugin_admin_notice' ], 99);
106 }
107
108 /**
109 * This method is reponsible for Admin Menu of
110 * NotificationX
111 *
112 * @return void
113 */
114 public function menu(){
115 add_menu_page(
116 'NotificationX',
117 'NotificationX',
118 'read_notificationx', // User Permision.
119 'nx-admin',
120 array( $this, 'views' ),
121 self::ASSET_URL . 'images/logo-icon.svg',
122 80
123 );
124 add_submenu_page( 'nx-admin', __('All NotificationX', 'notificationx'), __('All NotificationX', 'notificationx'), 'read_notificationx', 'nx-admin', null, 1 );
125 }
126
127 /**
128 * Admin Views
129 *
130 * @return void
131 */
132 public function views() {
133 // react script included in PostType::admin_enqueue_scripts();
134 include_once Admin::VIEWS_PATH . 'main.views.php';
135 }
136 /**
137 * Get File Modification Time or URL
138 *
139 * @param string $file File relative path for Admin
140 * @param boolean $url true for URL return
141 * @return void|string|integer
142 */
143 public function file( $file, $url = false ){
144 if( $url ) {
145 return self::ASSET_URL . $file;
146 }
147 return filemtime( self::ASSET_PATH . $file );
148 }
149
150 /**
151 * This method is responsible for re generating notification for single type.
152 * @param string $current_url
153 * @since 1.4.0
154 */
155 public function regenerate_notifications($params) {
156 $post_id = intval($params['nx_id']);
157 // @todo should not query the settings here. source and other two should be passed in param.
158 $post = PostType::get_instance()->get_post($post_id);
159 $source = isset($post['source']) ? $post['source'] : false;
160 $extension = ExtensionFactory::get_instance()->get($source);
161 if (!empty($extension) && method_exists($extension, 'get_notification_ready') && $extension->is_active()) {
162 Entries::get_instance()->delete_entries($post_id);
163 $result = $extension->get_notification_ready($post, $post_id);
164 return true;
165 }
166 return false;
167 }
168
169 /**
170 * This method is responsible for re generating notification for single type.
171 * @param string $current_url
172 * @since 1.4.0
173 */
174 public function reset_notifications($params) {
175 $nx_id = null;
176 if (!empty($entry_key)) {
177 $nx_id = $params['entry_key'];
178 }
179 if (!empty($params['nx_id'])) {
180 $nx_id = $params['nx_id'];
181 }
182 if (!empty($nx_id)) {
183 return Analytics::get_instance()->delete_analytics($nx_id);
184 }
185 }
186
187
188
189 public function admin_notices(){
190 self::$cache_bank = CacheBank::get_instance();
191 try {
192 $this->notices();
193 } catch ( \Exception $e ) {
194 unset( $e );
195 }
196 // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice)
197 NoticeRemover::get_instance( '1.0.0' );
198 }
199
200
201 public function hide_others_plugin_admin_notice()
202 {
203 $current_screen = get_current_screen();
204 $hide_on = ['toplevel_page_nx-admin', 'notificationx_page_nx-dashboard', 'notificationx_page_nx-edit','notificationx_page_nx-settings','notificationx_page_nx-analytics','notificationx_page_nx-builder', 'notificationx_page_nx-feedback-entries'];
205 if ( $current_screen && isset( $current_screen->base ) && in_array($current_screen->base, $hide_on) ) {
206 remove_all_actions('user_admin_notices');
207 remove_all_actions('admin_notices');
208 }
209 }
210
211 public function notices() {
212 $notices = new Notices([
213 'id' => 'notificationx',
214 'store' => 'options',
215 'storage_key' => 'notices',
216 'version' => '1.0.0',
217 'lifetime' => 3,
218 'stylesheet_url' => '',
219 'styles' => self::ASSET_URL . 'css/wpdeveloper-review-notice.css',
220 'priority' => 5,
221 // 'dev_mode' => true
222 ]);
223
224 $_review_notice = [
225 'thumbnail' => self::ASSET_URL . 'images/nx-icon.svg',
226 'html' => '<p>'. __( 'We hope you\'re enjoying NotificationX! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'notificationx' ) .'</p>',
227 'links' => [
228 'later' => array(
229 'link' => 'https://wpdeveloper.com/review-notificationx',
230 'target' => '_blank',
231 'label' => __( 'Ok, you deserve it!', 'notificationx' ),
232 'icon_class' => 'dashicons dashicons-external',
233 ),
234 'allready' => array(
235 'label' => __( 'I already did', 'notificationx' ),
236 'icon_class' => 'dashicons dashicons-smiley',
237 'attributes' => [
238 'data-dismiss' => true
239 ],
240 ),
241 'maybe_later' => array(
242 'label' => __( 'Maybe Later', 'notificationx' ),
243 'icon_class' => 'dashicons dashicons-calendar-alt',
244 'attributes' => [
245 'data-later' => true
246 ],
247 ),
248 'support' => array(
249 'link' => 'https://wpdeveloper.com/support',
250 'label' => __( 'I need help', 'notificationx' ),
251 'icon_class' => 'dashicons dashicons-sos',
252 ),
253 'never_show_again' => array(
254 'label' => __( 'Never show again', 'notificationx' ),
255 'icon_class' => 'dashicons dashicons-dismiss',
256 'attributes' => [
257 'data-dismiss' => true
258 ],
259 )
260 ]
261 ];
262
263 $notices->add(
264 'review',
265 $_review_notice,
266 [
267 'start' => $notices->strtotime( '+7 day' ),
268 'recurrence' => 30,
269 'dismissible' => true,
270 'refresh' => NOTIFICATIONX_VERSION,
271 ]
272 );
273
274 $notices->add(
275 'opt_in',
276 [ $this->insights, 'notice' ],
277 [
278 'classes' => 'updated put-dismiss-notice',
279 'start' => $notices->strtotime( '+30 days' ),
280 'dismissible' => true,
281 'refresh' => NOTIFICATIONX_VERSION,
282 'do_action' => 'wpdeveloper_notice_clicked_for_notificationx',
283 'display_if' => ! is_array( $notices->is_installed( 'notificationx-pro/notificationx-pro.php' ) )
284 ]
285 );
286
287 $notice_text = sprintf('<div style="display: flex; align-items: center;">%s <a class="button button-primary" style="margin-left: 10px; background: #5614d5; border-color: #5614d5;" target="_blank" href="%s">%s</a></div>', __( '<p><strong>Black Friday Exclusive:</strong> SAVE up to 40% & access to <strong>NotificationX Pro</strong> features.</p>', 'notificationx' ), esc_url( 'https://notificationx.com/#pricing' ), __('Grab The Offer', 'notificationx') );
288
289 $_black_friday = [
290 'thumbnail' => self::ASSET_URL . 'images/nx-icon.svg',
291 'html' => $notice_text,
292 ];
293
294 $notices->add(
295 'black_friday',
296 $_black_friday,
297 [
298 'start' => $notices->time(),
299 'recurrence' => false,
300 'dismissible' => true,
301 'expire' => strtotime( 'Wed, 30 Nov 2022 23:59:59 GMT' ),
302 'display_if' => ! is_array( $notices->is_installed( 'notificationx-pro/notificationx-pro.php' ) )
303 ]
304 );
305
306
307 // New Notice
308 $b_message = '<p>6th Anniversary Sale: Unlock premium features with <strong>up to 25% discounts</strong> & skyrocket your conversions 🚀</p><a class="button button-primary" href="https://wpdeveloper.com/upgrade/notificationx-bfcm" target="_blank">Upgrade to PRO</a>';
309 $_black_friday_notice = [
310 'thumbnail' => self::ASSET_URL . 'images/full-logo.svg',
311 'html' => $b_message,
312 ];
313
314 $notices->add(
315 '6th_anniversary',
316 $_black_friday_notice,
317 [
318 'start' => $notices->time(),
319 'recurrence' => false,
320 'dismissible' => true,
321 'refresh' => NOTIFICATIONX_VERSION,
322 "expire" => strtotime( '11:59:59pm 20th September, 2024' ),
323 // 'display_if' => ! is_plugin_active( 'notificationx-pro/notificationx-pro.php' )
324 ]
325 );
326
327 $crown = self::ASSET_URL . 'images/crown.svg';
328 // February Deal
329 $_february_deal = "<p>Boost trust & conversions with real-time social proof notification alerts – now <strong>Flat 20% OFF! 🎁</strong></p>
330 <div class='nx-notice-action-button'>
331 <a style='display: inline-flex;column-gap:5px;' class='button button-primary' href='https://notificationx.com/feb2026-admin-notice' target='_blank'>
332 Upgrade To PRO
333 </a>
334 <a class='nx-notice-action-dismiss dismiss-btn' data-dismiss='true' href='#'>
335 I’ll Grab It Later
336 </a>
337 </div>
338 ";
339 $_february_deal_html = [
340 'thumbnail' => self::ASSET_URL . 'images/full-logo.svg',
341 'html' => $_february_deal,
342 ];
343 $notices->add(
344 'nx_february_deal',
345 $_february_deal_html,
346 [
347 'start' => strtotime('11:59:59pm 9th February, 2026'),
348 'recurrence' => false,
349 'dismissible' => true,
350 'refresh' => NOTIFICATIONX_VERSION,
351 'screens' => [ 'dashboard' ],
352 "expire" => strtotime('11:59:59pm 7th March, 2026'),
353 'display_if' => !is_array( $notices->is_installed( 'notificationx-pro/notificationx-pro.php' ) )
354 ]
355 );
356
357 // Spring Campaign 2026
358 $_spring_deal = "<p><strong>🌸 Spring Savings:</strong> Boost conversions with real-time social proof & AI-powered notification alerts – now <strong>Flat 25% OFF!</strong> ⚡️</p>
359 <div class='nx-notice-action-button'>
360 <a style='display: inline-flex;column-gap:5px;' class='button button-primary' href='https://notificationx.com/spring2026-admin-notice' target='_blank'>
361 Upgrade To Pro Now
362 </a>
363 <a class='nx-notice-action-dismiss dismiss-btn' data-dismiss='true' href='#'>
364 Maybe Later
365 </a>
366 </div>
367 ";
368 $_spring_deal_html = [
369 'thumbnail' => self::ASSET_URL . 'images/full-logo.svg',
370 'html' => $_spring_deal,
371 ];
372 $notices->add(
373 'nx_spring_deal_2026',
374 $_spring_deal_html,
375 [
376 'start' => strtotime('12:00:00am 8th April, 2026'),
377 'recurrence' => false,
378 'dismissible' => true,
379 'refresh' => NOTIFICATIONX_VERSION,
380 'screens' => [ 'dashboard' ],
381 "expire" => strtotime('11:59:59pm 10th May, 2026'),
382 'display_if' => !is_array( $notices->is_installed( 'notificationx-pro/notificationx-pro.php' ) )
383 ]
384 );
385
386 // nx_summer_deal_2026 notice
387 $_nx_summer_deal_2026_text = "<p>🏖️ Turn visitors into buyers — faster. Launch real-time social proof & AI-powered alerts that drive conversions <strong>- up to \$150 OFF!</strong></p>
388 <div class='nx-notice-action-button' style='display: inline-flex;column-gap:5px;align-items:center;'>
389 <a class='button button-primary' href='https://notificationx.com/summer2026-admin-notice' target='_blank'>Upgrade To Pro Now</a> <a class='nx-notice-action-dismiss dismiss-btn' data-dismiss='true' href='#'>I Don't Want Any Discount</a>
390 </div>";
391 $_nx_summer_deal_2026 = [
392 'thumbnail' => self::ASSET_URL . 'images/full-logo.svg',
393 'html' => $_nx_summer_deal_2026_text,
394 ];
395 $notices->add(
396 'nx_summer_deal_2026',
397 $_nx_summer_deal_2026,
398 [
399 'start' => $notices->time(),
400 'recurrence' => false,
401 'dismissible' => true,
402 'refresh' => NOTIFICATIONX_VERSION,
403 'screens' => [ 'dashboard' ],
404 "expire" => strtotime( '11:59:59pm 25th June, 2026' ),
405 'display_if' => !is_array( $notices->is_installed( 'notificationx-pro/notificationx-pro.php' ) )
406 ]
407 );
408
409 // $notices->init();
410 self::$cache_bank->create_account( $notices );
411 self::$cache_bank->calculate_deposits( $notices );
412 }
413
414 public function plugin_usage_insights(){
415 $this->insights = PluginInsights::get_instance( NOTIFICATIONX_FILE, [
416 'opt_in' => true,
417 'goodbye_form' => true,
418 'item_id' => '6ba8d30bc0beaddb2540'
419 ] );
420 $this->insights->set_notice_options(array(
421 'notice' => __( 'Want to help make <strong>NotificationX</strong> even more awesome? You can get a <strong>10% discount coupon</strong> for Premium extensions if you allow us to track the usage.', 'notificationx' ),
422 'extra_notice' => __( 'We collect non-sensitive diagnostic data and plugin usage information.
423 Your site URL, WordPress & PHP version, plugins & themes and email address to send you the
424 discount coupon. This data lets us make sure this plugin always stays compatible with the most
425 popular plugins and themes. No spam, I promise.', 'notificationx' ),
426 ));
427 $this->insights->init();
428 }
429
430 /**
431 * Handle miscellaneous REST API actions
432 *
433 * @param mixed $result
434 * @param array $params
435 * @return mixed
436 */
437 public function handle_miscellaneous_actions($result, $params) {
438 if (isset($params['action']) && $params['action'] === 'dismiss_initial_popup') {
439 return $this->dismiss_initial_popup();
440 }
441 return $result;
442 }
443
444 /**
445 * Dismiss the initial popup
446 *
447 * @return bool
448 */
449 public function dismiss_initial_popup() {
450 // Check user permissions
451 if (!current_user_can('manage_options')) {
452 return false;
453 }
454
455 // Update the option to mark popup as dismissed
456 update_option('nx_force_popup_dismissed', '1');
457 $result = update_option('nx_initial_popup_dismissed', true);
458
459 return $result;
460 }
461
462 /**
463 * Check if popup should be shown
464 *
465 * @return bool
466 */
467 public function should_show_initial_popup() {
468 // Don't show if already dismissed
469 if (get_option('nx_initial_popup_dismissed', false)) {
470 return false;
471 }
472
473 // Don't show for non-admin users
474 if (!current_user_can('manage_options')) {
475 return false;
476 }
477
478 // Delay the popup until 1 day after installation. Quick Setup already
479 // handles onboarding, so this stays out of the way on the first day.
480 $install_time = get_option('nx_initial_popup_install_time', false);
481 if (!$install_time) {
482 $install_time = time();
483 update_option('nx_initial_popup_install_time', $install_time);
484 }
485
486 if ((time() - (int) $install_time) < DAY_IN_SECONDS) {
487 return false;
488 }
489
490 return true;
491 }
492
493 /**
494 * Add popup status to admin context
495 *
496 * @param array $data
497 * @return array
498 */
499 public function add_popup_status_to_context($data) {
500 $data['show_initial_popup'] = $this->should_show_initial_popup();
501 $data['nx_admin_notice_close'] = get_option('nx_admin_notice_close', false);
502 return $data;
503 }
504 }
505