PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.3.0
Adminify – White Label, Admin Menu Editor, Login Customizer v4.3.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Notifications / Notifications.php

Notifications.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.3.0, at Inc/Classes/Notifications/Notifications.php

270 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Classes\Notifications;
4
5 use PXLBSAdminify\Inc\Classes\Notifications\Base\Date;
6 use PXLBSAdminify\Inc\Classes\Helper;
7 // No, Direct access Sir !!!
8 if ( !defined( 'ABSPATH' ) ) {
9 exit;
10 }
11 /**
12 * Notification Class
13 *
14 * Jewel Theme <support@jeweltheme.com>
15 */
16 class Notifications {
17 use Date;
18 public $manager;
19
20 public $conflict_days = 5;
21
22 public $slug;
23
24 /**
25 * Construction method
26 */
27 public function __construct() {
28 $this->manager = new Manager();
29 $this->slug = Helper::slug_cleanup();
30 add_action( 'admin_print_scripts', array($this, 'init_notifications'), 99999999 );
31 add_action(
32 'pxlbsadminify_display_notice',
33 array($this, 'display_notice'),
34 10,
35 2
36 );
37 add_action(
38 'pxlbsadminify_display_popup',
39 array($this, 'display_popup'),
40 10,
41 2
42 );
43 add_action( 'wp_ajax_pxlbsadminify_notification_action', array($this, 'pxlbsadminify_notification_action') );
44 }
45
46 /**
47 * Notification Action
48 *
49 * @author Jewel Theme <support@jeweltheme.com>
50 */
51 public function pxlbsadminify_notification_action() {
52 check_ajax_referer( 'pxlbsadminify_notification_nonce' );
53 // Security check - only administrators can manage notifications
54 if ( !current_user_can( 'manage_options' ) ) {
55 wp_send_json_error( array(
56 'message' => __( 'You do not have permission to perform this action.', 'adminify' ),
57 ) );
58 }
59 $action_type = ( !empty( $_REQUEST['action_type'] ) ? sanitize_key( $_REQUEST['action_type'] ) : '' );
60 $notification_type = ( !empty( $_REQUEST['notification_type'] ) ? sanitize_key( $_REQUEST['notification_type'] ) : '' );
61 $trigger_time = ( !empty( $_REQUEST['trigger_time'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['trigger_time'] ) ) : '' );
62 $exec_notifications = $this->manager->get_exec_notifications( $trigger_time, $notification_type );
63 // No Executable Notifications found .
64 if ( empty( $exec_notifications ) ) {
65 die( 0 );
66 }
67 $count = 0;
68 foreach ( $exec_notifications as $index => $notification ) {
69 if ( 0 === $index ) {
70 if ( 'disable' === $action_type ) {
71 $notification->is_active = false;
72 }
73 $notification->fire( $trigger_time, $notification_type )->save();
74 } else {
75 $count++;
76 $notification->maybe_delay( $this->date_increment( $trigger_time, $this->conflict_days * $count ) )->save();
77 }
78 }
79 die( 0 );
80 }
81
82 /**
83 * Notification Setup
84 *
85 * @param [type] $type .
86 *
87 * @author Jewel Theme <support@jeweltheme.com>
88 */
89 public function setup_notifications_by_type( $type ) {
90 // $trigger_time should be today .
91 $trigger_time = $this->current_time();
92 // Block if necessary .
93 $notification_last_fired = get_option( "pxlbsadminify_{$type}_last_interact" );
94 if ( $notification_last_fired ) {
95 $notification_enable_date = $this->date_increment( $notification_last_fired, $this->conflict_days );
96 if ( $this->date_is_prev( $trigger_time, $notification_enable_date ) ) {
97 return;
98 }
99 }
100 // Get Executable Notifications .
101 $exec_notifications = $this->manager->get_exec_notifications( $trigger_time, $type );
102 // No Executable Notifications found .
103 if ( empty( $exec_notifications ) ) {
104 return;
105 }
106 $notification = $exec_notifications[0];
107 do_action( "pxlbsadminify_display_{$type}", $notification, $trigger_time );
108 }
109
110 /**
111 * Notification initialization
112 *
113 * @author Jewel Theme <support@jeweltheme.com>
114 */
115 public function init_notifications() {
116 add_action( 'admin_notices', array($this, 'setup_notifications') );
117 add_action( 'network_admin_notices', array($this, 'setup_notifications') );
118 }
119
120 /**
121 * Notification setup
122 *
123 * @author Jewel Theme <support@jeweltheme.com>
124 */
125 public function setup_notifications() {
126 $this->setup_notifications_by_type( 'notice' );
127 $this->setup_notifications_by_type( 'popup' );
128 }
129
130 /**
131 * Display notice
132 *
133 * @param [type] $notice .
134 * @param [type] $trigger_time .
135 *
136 * @return void
137 * @author Jewel Theme <support@jeweltheme.com>
138 */
139 public function display_notice( $notice, $trigger_time ) {
140 $notice->notice_header();
141 $notice->notice_content();
142 $notice->notice_footer();
143 $notice->core_script( $trigger_time );
144 }
145
146 /**
147 * Display Popup
148 *
149 * @param [type] $popup .
150 * @param [type] $trigger_time .
151 *
152 * @return void
153 * @author Jewel Theme <support@jeweltheme.com>
154 */
155 public function display_popup( $popup, $trigger_time ) {
156 $screen = get_current_screen();
157 if ( !in_array( $screen->id, ['toplevel_page_wp-adminify-settings', 'dashboard'] ) ) {
158 return;
159 }
160 $image_url = $popup->get_content( 'image_url' );
161 ?>
162
163 <div class="wp-adminify-popup" id="wp-adminify-popup" data-plugin="<?php
164 echo esc_attr( $this->slug );
165 ?>" tabindex="1">
166
167 <div class="wp-adminify-popup-overlay"></div>
168
169 <div class="wp-adminify-popup-modal" style="background-image: url('<?php
170 echo esc_url( $image_url );
171 ?>'); --wp-adminify-popup-color: <?php
172 echo esc_attr( $popup->get_content( 'btn_color' ) );
173 ?>;">
174
175 <!-- close -->
176 <div class="wp-adminify-popup-modal-close popup-dismiss">×</div>
177
178 <!-- content section -->
179 <div class="wp-adminify-popup-modal-footer">
180
181 <!-- countdown -->
182 <div class="wp-adminify-popup-countdown" style="display: none;">
183 <span class="wp-adminify-popup-countdown-text"><?php
184 echo esc_html__( 'Deal Ends In', 'adminify' );
185 ?></span>
186 <div class="wp-adminify-popup-countdown-time">
187 <div>
188 <span data-counter="days">00</span>
189 <span><?php
190 echo esc_html__( 'Days', 'adminify' );
191 ?></span>
192 </div>
193 <span>:</span>
194 <div>
195 <span data-counter="hours">00</span>
196 <span><?php
197 echo esc_html__( 'Hours', 'adminify' );
198 ?></span>
199 </div>
200 <span>:</span>
201 <div>
202 <span data-counter="minutes">00</span>
203 <span><?php
204 echo esc_html__( 'Minutes', 'adminify' );
205 ?></span>
206 </div>
207 <span>:</span>
208 <div>
209 <span data-counter="seconds">00</span>
210 <span><?php
211 echo esc_html__( 'Seconds', 'adminify' );
212 ?></span>
213 </div>
214 </div>
215 </div>
216
217 <!-- button -->
218 <a class="wp-adminify-popup-button" style="color: #fff !important" target="_blank" href="<?php
219 echo esc_url( $popup->get_content( 'button_url' ) );
220 ?>">
221 <?php
222 if ( jltwp_adminify()->can_use_premium_code() ) {
223 echo esc_html__( 'Upgrade Now', 'adminify' );
224 } else {
225 echo esc_html( $popup->get_content( 'button_text' ) );
226 }
227 ?>
228 </a>
229 </div>
230 </div>
231 </div>
232
233 <script>
234 function pxlbsadminify_popup_action(evt, $this, $action_type) {
235
236 evt.preventDefault();
237
238 $this.closest('.wp-adminify-popup').fadeOut(200);
239
240 jQuery.post('<?php
241 echo esc_url( admin_url( 'admin-ajax.php' ) );
242 ?>', {
243 action: 'pxlbsadminify_notification_action',
244 _wpnonce: '<?php
245 echo esc_js( wp_create_nonce( 'pxlbsadminify_notification_nonce' ) );
246 ?>',
247 action_type: $action_type,
248 notification_type: 'popup',
249 trigger_time: '<?php
250 echo esc_attr( $trigger_time );
251 ?>'
252 });
253 }
254
255 // Notice Dismiss
256 jQuery('body').on('click', '.wp-adminify-popup .popup-dismiss', function(evt) {
257 pxlbsadminify_popup_action(evt, jQuery(this), 'dismiss');
258 });
259
260 // Notice Disable
261 jQuery('body').on('click', '.wp-adminify-popup .popup-disable', function(evt) {
262 pxlbsadminify_popup_action(evt, jQuery(this), 'disable');
263 });
264 </script>
265
266 <?php
267 }
268
269 }
270