PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.3
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.3
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.1.3, at Inc/Classes/Notifications/Notifications.php

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