PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 1.0.3
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v1.0.3
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 / class-nx-message.php

class-nx-message.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 1.0.3, at includes/class-nx-message.php

873 lines 31.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class NotificationX_Notice {
3 /**
4 * Admin Notice Key
5 *
6 * @var array
7 */
8 const ADMIN_UPDATE_NOTICE_KEY = 'wpdeveloper_notices_seen';
9 public $text_domain = 'notificationx';
10 /**
11 * All Data
12 * @var array
13 */
14 private $data = array();
15 private $properties = array(
16 'links', 'message', 'thumbnail',
17 );
18 private $methods = array(
19 'message', 'thumbnail', 'classes'
20 );
21 /**
22 * cne_day == current_notice_end_day
23 *
24 * @var integer
25 */
26 public $cne_time = '2 day';
27 public $maybe_later_time = '7 day';
28 /**
29 * Plugin Name
30 *
31 * @var string
32 */
33 private $plugin_name;
34 /**
35 * Plugin File Name
36 * @var string
37 */
38 private $plugin_file;
39 /**
40 * First Install Version Of The Plugin
41 *
42 * @var string
43 */
44 private $version;
45 /**
46 * Saved Data in DB
47 * @var array
48 */
49 private $options_data;
50 /**
51 * Current Timestamp
52 * @var integer
53 */
54 public $timestamp;
55 /**
56 * Primary Notice Action
57 *
58 * @var string
59 */
60 private $do_notice_action;
61 /**
62 * Default Options Set
63 *
64 * @var array
65 */
66 public $options_args = array(
67 // 'first_install' => true,
68 // 'notice_will_show' => [
69 // 'opt_in' => true,
70 // 'first_install' => false,
71 // 'update' => true,
72 // 'review' => true,
73 // 'upsale' => true,
74 // ]
75 );
76 /**
77 * Notice ID for users.
78 * @var string
79 */
80 private $notice_id;
81 /**
82 * Upsale Notice Arguments
83 * @var array
84 */
85 public $upsale_args;
86 /**
87 * Revoke this function when the object is created.
88 *
89 * @param string $plugin_name
90 * @param string $version
91 */
92 public function __construct( $plugin_file = '', $version = '' ) {
93 $this->plugin_file = $plugin_file;
94 $this->plugin_name = basename( $plugin_file, '.php' );
95 $this->version = $version;
96 $this->timestamp = intval( current_time( 'timestamp' ) );
97 $this->notice_id = 'wpdeveloper_notice_' . str_replace( '.', '_', $this->version );
98
99 $this->do_notice_action = 'wpdeveloper_notices_for_' . $this->plugin_name;
100
101 if( ! class_exists( 'NotificationX_Core_Installer' ) ) {
102 require_once dirname( __FILE__ ) . '/class-nx-core-installer.php';
103 new NotificationX_Core_Installer( $this->plugin_name );
104 }
105 }
106 /**
107 * Initiate The Plugin
108 * @return void
109 */
110 public function init(){
111 add_action( 'init', array( $this, 'first_install_track') );
112 add_action( 'deactivate_' . $this->plugin_file, array( $this, 'first_install_end' ) );
113 add_action( 'init', array( $this, 'hooks' ) );
114 }
115 /**
116 * All Hooks
117 * @return void
118 */
119 public function hooks(){
120 add_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name, array( $this, 'clicked' ) );
121 add_action( 'wp_ajax_wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'upsale_notice_dissmiss' ) );
122 add_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name, array( $this, 'before' ) );
123 add_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
124 add_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name, array( $this, 'before_upsale' ) );
125 add_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
126 add_action( $this->do_notice_action, array( $this, 'content' ) );
127 if( current_user_can( 'install_plugins' ) ) {
128 if( isset( $_GET['plugin'] ) && $_GET['plugin'] == $this->plugin_name ) {
129 do_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name );
130 /**
131 * Redirect User To the Current URL, but without set query arguments.
132 */
133 wp_safe_redirect( $this->redirect_to() );
134 }
135 $return_notice = $this->next_notice();
136 $current_notice = current( $return_notice );
137 $next_notice = next( $return_notice );
138
139 $deserve_notice = $this->deserve_notice( $current_notice );
140 $options_data = $this->get_options_data();
141 $user_notices = $this->get_user_notices();
142
143 $notice_time = isset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] )
144 ? $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] : $this->timestamp;
145 $next_notice_time = $next_notice ? $options_data[ $this->plugin_name ]['notice_will_show'][ $next_notice ] : $this->timestamp;
146 $current_notice_end = $this->makeTime( $notice_time, $this->cne_time );
147
148 if( ! $deserve_notice ) {
149 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
150 $this->update_options_data( $options_data[ $this->plugin_name ] );
151 }
152
153 if( $deserve_notice ) {
154 /**
155 * TODO: automatic maybe later setup with time.
156 */
157 if( ( $this->timestamp >= $current_notice_end ) || ( $this->timestamp > $next_notice_time ) ) {
158 $this->maybe_later( $current_notice );
159 $notice_time = false;
160 }
161 if( $notice_time != false ) {
162 if( $notice_time <= $this->timestamp ) {
163 if( $current_notice === 'upsale' ) {
164 $upsale_args = $this->get_upsale_args();
165 if ( ! function_exists( 'get_plugins' ) ) {
166 include ABSPATH . '/wp-admin/includes/plugin.php';
167 }
168 $plugins = get_plugins();
169 $pkey = $upsale_args['slug'] . '/' . $upsale_args['file'];
170 if( isset( $plugins[ $pkey ] ) ) {
171 $this->update( $current_notice );
172 return;
173 }
174 add_action( 'admin_notices', array( $this, 'upsale_notice' ) );
175 } else {
176 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
177 }
178 }
179 }
180 }
181 }
182 }
183 /**
184 * Make time using timestamp and a string like 2 Hour, 2 Day, 30 Minutes, 1 Week, 1 year
185 * @param integer $current
186 * @param string $time
187 * @return integer
188 */
189 public function makeTime( $current, $time ) {
190 return intval( strtotime( date('Y-m-d H:i:s', $current) . " +$time" ) );
191 }
192 /**
193 * Automatice Maybe Later.
194 * @param string $notice
195 * @return void
196 */
197 private function maybe_later( $notice ){
198 if( empty( $notice ) ) {
199 return;
200 }
201 $options_data = $this->get_options_data();
202 $options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] = $this->makeTime( $this->timestamp, $this->maybe_later_time );
203 $this->update_options_data( $options_data[ $this->plugin_name ] );
204 }
205 /**
206 * When links are clicked, this function will invoked.
207 * @return void
208 */
209 public function clicked(){
210 if( isset( $_GET['plugin'] ) && $_GET['plugin'] === $this->plugin_name ) {
211 $options_data = $this->get_options_data();
212 $clicked_from = current( $this->next_notice() );
213 extract($_GET);
214
215 $later_time = '';
216
217 switch( $clicked_from ) {
218
219 case 'opt_in' :
220 $dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
221 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
222 break;
223
224 case 'first_install' :
225 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
226 break;
227
228 case 'update' :
229 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
230 break;
231
232 case 'review' :
233 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
234 break;
235
236 case 'upsale' :
237 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
238 break;
239 }
240
241 if( isset( $later ) && $later == true ) {
242 $options_data[ $this->plugin_name ]['notice_will_show'][ $clicked_from ] = $later_time;
243 }
244 if( isset( $dismiss ) && $dismiss == true ) {
245 $this->update( $clicked_from );
246 }
247 $this->update_options_data( $options_data[ $this->plugin_name ] );
248 }
249 }
250 /**
251 * For Redirecting Current Page without Arguments!
252 *
253 * @return void
254 */
255 private function redirect_to(){
256 $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
257 $query_string = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY );
258 parse_str( $query_string, $current_url );
259
260 $unset_array = array( 'dismiss', 'plugin', '_wpnonce', 'later', 'plugin_action', 'marketing_optin' );
261
262 foreach( $unset_array as $value ) {
263 if( isset( $current_url[ $value ] ) ) {
264 unset( $current_url[ $value ] );
265 }
266 }
267
268 $current_url = http_build_query($current_url);
269 $redirect_url = $request_uri . '?' . $current_url;
270 return $redirect_url;
271 }
272 /**
273 * Before Notice
274 * @return void
275 */
276 public function before(){
277 $current_notice = current( $this->next_notice() );
278 $classes = 'notice notice-info put-dismiss-notice';
279 if( isset( $this->data['classes'] ) ) {
280 if( isset( $this->data['classes'][ $current_notice ] ) ) {
281 $classes = $this->data['classes'][ $current_notice ];
282 }
283 }
284
285 if( $this->has_thumbnail( $current_notice ) ) {
286 $classes .= 'notice-has-thumbnail';
287 }
288
289 echo '<div class="'. $classes .' wpdeveloper-'. $current_notice .'-notice">';
290 }
291 /**
292 * After Notice
293 * @return void
294 */
295 public function after(){
296 echo '</div>';
297 }
298 /**
299 * Content generation & Hooks Funciton.
300 * @return void
301 */
302 public function content(){
303 $options_data = $this->get_options_data();
304 $notice = current( $this->next_notice() );
305
306 switch( $notice ) {
307 case 'opt_in' :
308 do_action('wpdeveloper_optin_notice_for_' . $this->plugin_name );
309 break;
310 case 'first_install' :
311 if( $options_data[ $this->plugin_name ]['first_install'] !== 'deactivated' ) {
312 do_action( 'wpdeveloper_first_install_notice_for_' . $this->plugin_name );
313 $this->get_thumbnail( 'first_install' );
314 $this->get_message( 'first_install' );
315 }
316 break;
317 case 'update' :
318 do_action( 'wpdeveloper_update_notice_for_' . $this->plugin_name );
319 $this->get_thumbnail( 'update' );
320 $this->get_message( 'update' );
321 break;
322 case 'review' :
323 do_action( 'wpdeveloper_review_notice_for_' . $this->plugin_name );
324 $this->get_thumbnail( 'review' );
325 $this->get_message( 'review' );
326 break;
327 }
328 }
329 /**
330 * Before Upsale Notice
331 * @return void
332 */
333 public function before_upsale(){
334 $classes = '';
335 if( $this->has_thumbnail('upsale') ) {
336 $classes = 'notice-has-thumbnail';
337 }
338 echo '<div class="error notice is-dismissible wpdeveloper-upsale-notice '. $classes .'">';
339 }
340 /**
341 * Upsale Notice
342 */
343 public function upsale_notice(){
344 do_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name );
345 do_action('wpdeveloper_upsale_notice_for_' . $this->plugin_name);
346 $this->get_thumbnail( 'upsale' );
347 $this->get_message( 'upsale' );
348 do_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name );
349 $this->upsale_button_script();
350 }
351 /**
352 * Get upsale arguments.
353 * @return void
354 */
355 private function get_upsale_args(){
356 return ( empty( $this->upsale_args ) ) ? array() : $this->upsale_args;
357 }
358 /**
359 * This function is responsible for making the button visible to the upsale notice.
360 */
361 private function upsale_button(){
362 $upsale_args = $this->get_upsale_args();
363 $plugin_slug = ( isset( $upsale_args['slug'] )) ? $upsale_args['slug'] : '' ;
364 if( empty( $plugin_slug ) ) {
365 return;
366 }
367 echo '<a href="https://wpdeveloper.net/in/notificationx-pro" class="button button-primary notificationx-notice-cta" target="_blank">'. __( 'Upgrade to Pro!', $this->text_domain ) .'</a>';
368 }
369 /**
370 * This methods is responsible for get notice image.
371 *
372 * @param string $msg_for
373 * @return void
374 */
375 protected function get_thumbnail( $msg_for ){
376 $output = '';
377 if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
378 $output = '<div class="wpdeveloper-notice-thumbnail">';
379 $output .= '<img src="'. $this->data['thumbnail'][ $msg_for ] .'" alt="">';
380 $output .= '</div>';
381 }
382 echo $output;
383 }
384 /**
385 * Has Thumbnail Check
386 *
387 * @param string $msg_for
388 * @return boolean
389 */
390 protected function has_thumbnail( $msg_for = '' ){
391 if( empty( $msg_for ) ) {
392 return false;
393 }
394 if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
395 return true;
396 }
397 return false;
398 }
399 /**
400 * This method is responsible for get messages.
401 *
402 * @param string $msg_for
403 * @return void
404 */
405 protected function get_message( $msg_for ){
406 if( isset( $this->data['message'] ) && isset( $this->data['message'][ $msg_for ] ) ) {
407 echo '<div class="wpdeveloper-notice-message">';
408 echo $this->data['message'][ $msg_for ];
409 if( $msg_for === 'upsale' ) {
410 $this->upsale_button();
411 }
412 $this->dismissible_notice( $msg_for );
413 echo '</div>';
414 }
415 }
416 /**
417 * Detect which notice will show @ next.
418 * @return void
419 */
420 protected function next_notice(){
421 $options_data = $this->get_options_data();
422 if( ! $options_data ) {
423 $args = $this->get_args();
424 $return_notice = $args['notice_will_show'];
425 } else {
426 $return_notice = $options_data[ $this->plugin_name ]['notice_will_show'];
427 }
428
429 if( is_array( $return_notice ) ) {
430 $return_notice = array_flip( $return_notice );
431 ksort( $return_notice );
432 }
433
434 return $return_notice;
435 }
436 /**
437 * Which notice is deserve to show in next slot.
438 * @param string $notice
439 * @return boolean
440 */
441 private function deserve_notice( $notice ) {
442 $notices = $this->get_user_notices();
443 if( $notice === false ) {
444 return false;
445 }
446 if( empty( $notices ) ) {
447 return true;
448 } else {
449 if( isset( $notices[ $this->notice_id ] ) && isset( $notices[ $this->notice_id ][ $this->plugin_name ] ) ) {
450 if( in_array( $notice, $notices[ $this->notice_id ][ $this->plugin_name ] ) ) {
451 return false;
452 } else {
453 return true;
454 }
455 } else {
456 return true;
457 }
458 }
459 }
460 /**
461 * This is the main methods for generate the notice.
462 * @return void
463 */
464 public function admin_notices(){
465 $current_notice = current( $this->next_notice() );
466 if( $current_notice == 'opt_in' ) {
467 do_action( $this->do_notice_action );
468 return;
469 }
470 do_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name );
471 do_action( $this->do_notice_action );
472 do_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name );
473 }
474 /**
475 * This method is responsible for all dismissible links generation.
476 * @param string $links_for
477 * @return void
478 */
479 public function dismissible_notice( $links_for = '' ){
480 if( empty( $links_for ) ) {
481 return;
482 }
483 $links = isset( $this->data['links'][ $links_for ] ) ? $this->data['links'][ $links_for ] : false;
484 if( $links ) :
485 $output = '<ul class="wpdeveloper-notice-link">';
486 foreach( $links as $key => $link_value ) {
487 if( ! empty( $link_value['label'] ) ) {
488 $output .= '<li>';
489 if( isset( $link_value['link'] ) ) {
490 $link = $link_value['link'];
491 $target = isset( $link_value['target'] ) ? 'target="'. $link_value['target'] .'"' : '';
492 if( isset( $link_value['data_args'] ) && is_array( $link_value['data_args'] ) ) {
493 $data_args = [];
494 foreach( $link_value['data_args'] as $key => $args_value ) {
495 $data_args[ $key ] = $args_value;
496 }
497 $data_args[ 'plugin' ] = $this->plugin_name;
498 $normal_link = add_query_arg( $data_args, $link );
499 $link = wp_nonce_url( $normal_link, 'wpdeveloper-nonce' );
500 }
501 $class = '';
502 if( isset( $link_value['link_class'] ) ) {
503 $class = 'class="' . implode( ' ', $link_value['link_class'] ) . '"';
504 }
505 $output .= '<a '. $class .' href="'. esc_url( $link ) .'" '. $target .'>';
506 }
507 if( isset( $link_value['icon_class'] ) ) {
508 $output .= '<span class="'. $link_value['icon_class'] .'"></span>';
509 }
510 if( isset( $link_value['icon_img'] ) ) {
511 $output .= '<img src="'. $link_value['icon_img'] .'" />';
512 }
513 $output .= $link_value['label'];
514 if( isset( $link_value['link'] ) ) {
515 $output .= '</a>';
516 }
517 $output .= '</li>';
518 }
519 }
520 $output .= '</ul>';
521 echo $output;
522 endif;
523 }
524 /**
525 * First Installation Track
526 * @return void
527 */
528 public function first_install_track( $args = array() ){
529 if( ! current_user_can( 'manage_options' ) ) {
530 return;
531 }
532 if( empty( $args ) ) {
533 $args = array(
534 'time' => $this->timestamp,
535 'version' => $this->version,
536 );
537 }
538 $options_data = $this->get_options_data();
539 $args = wp_parse_args( $args, $this->get_args() );
540 if( ! isset( $options_data[ $this->plugin_name ] )
541 || ( isset( $options_data[ $this->plugin_name ]['version'] ) && version_compare( $options_data[ $this->plugin_name ]['version'], $this->version, '!=' ) ) ) {
542 $this->update_options_data( $args );
543 }
544 }
545 /**
546 * First Installation Deactive Track
547 *
548 * @return void
549 */
550 public function first_install_end(){
551 // $args = array(
552 // 'first_install' => 'deactivated'
553 // );
554 // $options_data = $this->get_options_data();
555 // if( isset( $options_data[ $this->plugin_name ] ) ) {
556 // $args = wp_parse_args( $args, $options_data[ $this->plugin_name ] );
557 // $this->update_options_data( $args );
558 // }
559 delete_option( 'wpdeveloper_plugins_data' );
560 }
561 /**
562 * Get all options from database!
563 * @return void
564 */
565 protected function get_options_data( $key = ''){
566 $options_data = get_option( 'wpdeveloper_plugins_data' );
567 if( empty( $key ) ) {
568 return $options_data;
569 }
570
571 if( isset( $options_data[ $this->plugin_name ][ $key ] ) ) {
572 return $options_data[ $this->plugin_name ][ $key ];
573 }
574 return false;
575 }
576 /**
577 * This will update the options table for plugins.
578 *
579 * @param mixed $new_data
580 * @param array $args
581 * @return void
582 */
583 protected function update_options_data( $args = array() ){
584 $options_data = $this->get_options_data();
585 $options_data[ $this->plugin_name ] = $args;
586 update_option( 'wpdeveloper_plugins_data', $options_data );
587 }
588 /**
589 * Set properties data, for some selected properties.
590 *
591 * @param string $name
592 * @param mixed $value
593 */
594 public function __set( $name, $value ){
595 if( in_array( $name, $this->properties ) ) {
596 $this->data[ $name ] = $value;
597 }
598 }
599 /**
600 * Invoked when some selected methods are called
601 *
602 * @param string $name
603 * @param array $values
604 * @return void
605 */
606 public function __call( $name, $values ){
607 if( in_array( $name, $this->methods ) ) {
608 $this->data[ $name ][ $values[0] ] = $values[1];
609 }
610 }
611 /**
612 * Get all option arguments.
613 * @param string $key
614 * @return array
615 */
616 private function get_args( $key = '' ){
617 if( empty( $key ) ) {
618 return $this->options_args;
619 }
620
621 if( isset( $this->options_args[ $key ] ) ) {
622 return $this->options_args[ $key ];
623 }
624
625 return false;
626 }
627 /**
628 * Resetting data on update.
629 * @return void
630 */
631 private function set_args_on_update(){
632 $args = $this->get_args();
633 $options_data = $this->get_options_data();
634 $set_data = $options_data[ $this->plugin_name ];
635 $args = wp_parse_args( $set_data, $args );
636 $this->update_options_data( $args );
637 }
638 /**
639 * When upgrade is complete. it will fired.
640 * @param WP_Upgrader $upgrader_object
641 * @param array $options
642 * @return void
643 */
644 public function upgrade_completed( $upgrader_object, $options ) {
645 // If an update has taken place and the updated type is plugins and the plugins element exists
646 if( isset( $options['action'] ) && $options['action'] == 'update' && $options['type'] == 'plugin' ) {
647 if( ! isset( $options['plugin'] ) && isset( $options['plugins'] ) ) {
648 foreach( $options['plugins'] as $plugin ) {
649 if( $plugin == $this->plugin_name ) {
650 $this->set_args_on_update();
651 }
652 }
653 }
654
655 if( isset( $options['plugin'] ) && $options['plugin'] == $this->plugin_name ) {
656 $this->set_args_on_update();
657 }
658 }
659 }
660 /**
661 * This function is responsible for get_user_notices
662 * @return void
663 */
664 private function get_user_notices() {
665 $notices = get_user_meta( get_current_user_id(), self::ADMIN_UPDATE_NOTICE_KEY, true );
666 return ! $notices ? array() : $notices;
667 }
668 /**
669 * This function is responsible for update meta information.
670 *
671 * @param string $notice
672 * @return void
673 */
674 private function update( $notice ){
675 if( empty( $notice ) ) {
676 return;
677 }
678 $options_data = $this->get_options_data();
679 $user_notices = $this->get_user_notices();
680 $user_notices[ $this->notice_id ][ $this->plugin_name ][] = $notice;
681 // Remove the upsale from notice_will_show field in options DB.
682 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] );
683 $this->update_options_data( $options_data[ $this->plugin_name ] );
684 // Set users meta, not to show again current_version notice.
685 update_user_meta( get_current_user_id(), self::ADMIN_UPDATE_NOTICE_KEY, $user_notices);
686 }
687 /**
688 * This function is responsible for do action when
689 * the dismiss button clicked in upsale notice.
690 */
691 public function upsale_notice_dissmiss(){
692
693 if( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpdeveloper_upsale_notice_dissmiss' ) ) {
694 return;
695 }
696
697 if( ! isset( $_POST['action'] ) || ( $_POST['action'] !== 'wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name ) ) {
698 return;
699 }
700
701 $dismiss = isset( $_POST['dismiss'] ) ? $_POST['dismiss'] : false;
702 if( $dismiss ) {
703 $this->update( 'upsale' );
704 echo 'success';
705 } else {
706 echo 'failed';
707 }
708 die();
709 }
710 /**
711 * Upsale Button Script.
712 * When install button is clicked, it will do its own things.
713 * also for dismiss button JS.
714 * @return void
715 */
716 public function upsale_button_script(){
717 $upsale_args = $this->get_upsale_args();
718
719 $plugin_slug = ( isset( $upsale_args['slug'] ) ) ? $upsale_args['slug'] : '';
720 $plugin_file = ( isset( $upsale_args['file'] ) ) ? $upsale_args['file'] : '';
721 $page_slug = ( isset( $upsale_args['page_slug'] ) ) ? $upsale_args['page_slug'] : '';
722
723 ?>
724 <script type="text/javascript">
725 jQuery(document).ready( function($) {
726 <?php if( ! empty( $plugin_slug ) && ! empty( $plugin_file ) ) : ?>
727 $('#plugin-install-core-<?php echo $this->plugin_name; ?>').on('click', function (e) {
728 var self = $(this);
729 e.preventDefault();
730 self.addClass('install-now updating-message');
731 self.text('<?php echo esc_js( 'Installing...' ); ?>');
732
733 $.ajax({
734 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
735 type: 'POST',
736 data: {
737 action: 'wpdeveloper_upsale_core_install_<?php echo $this->plugin_name; ?>',
738 _wpnonce: '<?php echo wp_create_nonce('wpdeveloper_upsale_core_install_' . $this->plugin_name ); ?>',
739 slug : '<?php echo $plugin_slug; ?>',
740 file : '<?php echo $plugin_file; ?>'
741 },
742 success: function(response) {
743 self.text('<?php echo esc_js( 'Installed' ); ?>');
744 <?php if( ! empty( $page_slug ) ) : ?>
745 window.location.href = '<?php echo admin_url( "admin.php?page={$page_slug}" ); ?>';
746 <?php endif; ?>
747 },
748 error: function(error) {
749 self.removeClass('install-now updating-message');
750 alert( error );
751 },
752 complete: function() {
753 self.attr('disabled', 'disabled');
754 self.removeClass('install-now updating-message');
755 }
756 });
757 });
758
759 <?php endif; ?>
760
761 $('.wpdeveloper-upsale-notice').on('click', 'button.notice-dismiss', function (e) {
762 e.preventDefault();
763 $.ajax({
764 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
765 type: 'post',
766 data: {
767 action: 'wpdeveloper_upsale_notice_dissmiss_for_<?php echo $this->plugin_name; ?>',
768 _wpnonce: '<?php echo wp_create_nonce('wpdeveloper_upsale_notice_dissmiss'); ?>',
769 dismiss: true
770 },
771 success: function(response) {
772 console.log('Success fully saved!');
773 },
774 error: function(error) {
775 console.log('Something went wrong!');
776 },
777 complete: function() {
778 console.log('Its Complete.');
779 }
780 });
781 });
782 } );
783 </script>
784
785 <?php
786 }
787 }
788
789 // Initialization.
790 $notice = new NotificationX_Notice(NOTIFICATIONX_BASENAME, NOTIFICATIONX_VERSION);
791 $scheme = (parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY )) ? '&' : '?';
792 $url = $_SERVER['REQUEST_URI'] . $scheme;
793 $notice->links = [
794 'review' => array(
795 'later' => array(
796 'link' => 'https://wpdeveloper.net/review-notificationx',
797 'target' => '_blank',
798 'label' => __( 'Ok, you deserve it!', $notice->text_domain ),
799 'icon_class' => 'dashicons dashicons-external',
800 ),
801 'allready' => array(
802 'link' => $url,
803 'label' => __( 'I already did', $notice->text_domain ),
804 'icon_class' => 'dashicons dashicons-smiley',
805 'data_args' => [
806 'dismiss' => true,
807 ]
808 ),
809 'maybe_later' => array(
810 'link' => $url,
811 'label' => __( 'Maybe Later', $notice->text_domain ),
812 'icon_class' => 'dashicons dashicons-calendar-alt',
813 'data_args' => [
814 'later' => true,
815 ]
816 ),
817 'support' => array(
818 'link' => 'https://wpdeveloper.net/support',
819 'label' => __( 'I need help', $notice->text_domain ),
820 'icon_class' => 'dashicons dashicons-sos',
821 ),
822 'never_show_again' => array(
823 'link' => $url,
824 'label' => __( 'Never show again', $notice->text_domain ),
825 'icon_class' => 'dashicons dashicons-dismiss',
826 'data_args' => [
827 'dismiss' => true,
828 ]
829 ),
830 )
831 ];
832
833 /**
834 * This is upsale notice settings
835 * classes for wrapper,
836 * Message message for showing.
837 */
838 $notice->classes( 'upsale', 'notice is-dismissible' );
839 $notice->message( 'upsale', '<p>'. __( 'Get the missing feature for NotificationX by installing PRO!', $notice->text_domain ) .'</p>' );
840 $notice->thumbnail( 'upsale', plugins_url( 'admin/assets/img/nx-icon.svg', NOTIFICATIONX_BASENAME ) );
841
842 /**
843 * This is review message and thumbnail.
844 */
845 $notice->message( 'review', '<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?', $notice->text_domain ) .'</p>' );
846 $notice->thumbnail( 'review', plugins_url( 'admin/assets/img/nx-icon.svg', NOTIFICATIONX_BASENAME ) );
847
848 /**
849 * Current Notice End Time.
850 * Notice will dismiss in 3 days if user does nothing.
851 */
852 $notice->cne_time = '3 Day';
853 /**
854 * Current Notice Maybe Later Time.
855 * Notice will show again in 7 days
856 */
857 $notice->maybe_later_time = '7 Day';
858
859 $notice->upsale_args = array(
860 'slug' => 'notificationx-pro',
861 'page_slug' => 'nx-builder',
862 'file' => 'nx-pro.php'
863 );
864
865 $notice->options_args = array(
866 'notice_will_show' => [
867 'opt_in' => $notice->timestamp,
868 'review' => $notice->makeTime( $notice->timestamp, '7 Day' ), // after 4 days
869 'upsale' => $notice->makeTime( $notice->timestamp, '4 Day' ), // will be after 2 hours
870 ]
871 );
872
873 $notice->init();