PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.0.10
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.0.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / codeinwp / themeisle-sdk / class-themeisle-sdk-notification-manager.php

class-themeisle-sdk-notification-manager.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.0.10, at vendor/codeinwp/themeisle-sdk/class-themeisle-sdk-notification-manager.php

106 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The notification manager class for ThemeIsle SDK
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Notification
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15 if ( ! class_exists( 'ThemeIsle_SDK_Notification_Manager' ) ) :
16 /**
17 * Notification manager model for ThemeIsle SDK.
18 */
19 class ThemeIsle_SDK_Notification_Manager {
20 /**
21 * Time between notifications.
22 */
23 const NOTIFICATION_INTERVAL_HOURS = 100;
24 /**
25 * @var array Notifications for the current product.
26 */
27 static private $notifications = array();
28 /**
29 * @var ThemeIsle_SDK_Product Current product.
30 */
31 private $product;
32 /**
33 * @var array ThemeIsle_SDK_Feedback Feedbacks available.
34 */
35 private $callbacks = array();
36
37 /**
38 * ThemeIsle_SDK_Notification_Manager constructor.
39 *
40 * @param ThemeIsle_SDK_Product $product_object Product Object.
41 * @param array $callbacks the objects that will be called when a notification is due.
42 */
43 public function __construct( $product_object, $callbacks ) {
44 $this->product = $product_object;
45 $this->callbacks = $callbacks;
46 $this->setup_hooks();
47 }
48
49 /**
50 * Setup the notifications.
51 */
52 function setup_notifications() {
53 if ( ! current_user_can( 'manage_options' ) ) {
54 return;
55 }
56 // Load the notifications only if we have it installed after the required interval.
57 if ( ( time() - $this->product->get_install_time() ) > self::NOTIFICATION_INTERVAL_HOURS * HOUR_IN_SECONDS ) {
58 if ( $this->product instanceof ThemeIsle_SDK_Product && $this->callbacks && is_array( $this->callbacks ) ) {
59 foreach ( $this->callbacks as $instance ) {
60 self::$notifications[ $this->product->get_key() . get_class( $instance ) ] = $instance;
61 }
62 }
63 }
64 }
65
66 /**
67 * Setup the internal hooks
68 */
69 private function setup_hooks() {
70 add_action( 'admin_head', array( $this, 'show_notification' ) );
71 add_action( 'admin_init', array( $this, 'setup_notifications' ) );
72 }
73
74 /**
75 * Shows the notification
76 */
77 function show_notification() {
78 $instances = self::$notifications;
79 if ( empty( $instances ) ) {
80 return;
81 }
82
83 $available = array_keys( $instances );
84 $active = get_option( 'themeisle_sdk_active_notification', array() );
85
86 foreach ( $available as $key ) {
87 $instance = $instances[ $key ];
88 if ( $instance->can_notify() ) {
89
90 // Detect notification switch.
91 if ( empty( $active['key'] ) || ( $active['key'] != $key ) ) {
92 $active['key'] = $key;
93 $active['time'] = time();
94 update_option( 'themeisle_sdk_active_notification', $active );
95 }
96 if ( ( time() - $active['time'] ) > ( self::NOTIFICATION_INTERVAL_HOURS * HOUR_IN_SECONDS ) ) {
97 $instance->show_notification();
98 }
99 break;
100 }
101 }
102
103 }
104 }
105 endif;
106