PluginProbe ʕ •ᴥ•ʔ
Essential Addons for Elementor – Popular Elementor Templates & Widgets / 6.6.9
Essential Addons for Elementor – Popular Elementor Templates & Widgets v6.6.9
6.6.9 6.6.8 6.6.7 6.6.6 6.6.5 6.6.4 6.6.3 5.7.3 5.7.4 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.15 5.8.16 5.8.18 5.8.2 5.8.3 5.8.4 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.10 5.9.11 5.9.12 5.9.13 5.9.14 5.9.15 5.9.16 5.9.17 5.9.18 5.9.19 5.9.2 5.9.20 5.9.21 5.9.22 5.9.23 5.9.24 5.9.25 5.9.26 5.9.27 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.14 6.0.15 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.0 6.1.1 6.1.10 6.1.11 trunk 6.1.12 1.0.0 6.1.13 1.0.1 6.1.14 1.1.0 6.1.15 2.0 6.1.17 2.1 6.1.18 2.10.0 6.1.19 2.10.1 6.1.2 2.10.2 6.1.20 2.10.3 6.1.3 2.10.4 6.1.4 2.10.5 6.1.5 2.2.0 6.1.6 2.2.1 6.1.7 2.2.2 6.1.8 2.2.3 6.1.9 2.2.4 6.2.0 2.2.5 6.2.1 2.3.0 6.2.2 2.3.1 6.2.3 2.4.0 6.2.4 2.4.1 6.3.0 2.4.2 6.3.1 2.4.3 6.3.2 2.5.0 6.3.3 2.6.0 6.4.0 2.7.0 6.5.0 2.7.1 6.5.1 2.7.10 6.5.10 2.7.11 6.5.11 2.7.2 6.5.12 2.7.3 6.5.13 2.7.4 6.5.2 2.7.5 6.5.3 2.7.6 6.5.4 2.7.7 6.5.5 2.7.8 6.5.6 2.7.9 6.5.7 2.8.0 6.5.8 2.8.1 6.5.9 2.8.2 6.6.0 2.8.3 6.6.1 2.8.4 6.6.2 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.4.1 3.1.5 3.2.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 5.0.0 5.0.1 5.0.10 5.0.11 5.0.12 5.0.13 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.4.6 5.5.5 5.6.5 5.7.2
essential-addons-for-elementor-lite / includes / Classes / WPDeveloper_Notice.php
essential-addons-for-elementor-lite / includes / Classes Last commit date
AllTraits.php 1 year ago Asset_Builder.php 9 months ago Bootstrap.php 2 weeks ago Compatibility_Support.php 2 months ago Elements_Manager.php 7 months ago Helper.php 1 month ago Migration.php 5 months ago Plugin_Usage_Tracker.php 5 months ago WPDeveloper_Core_Installer.php 5 months ago WPDeveloper_Notice.php 2 months ago WPDeveloper_Plugin_Installer.php 5 months ago WPDeveloper_Setup_Wizard.php 2 months ago index.php 3 years ago
WPDeveloper_Notice.php
956 lines
1 <?php
2 namespace Essential_Addons_Elementor\Classes;
3
4 if (!defined('ABSPATH')) {
5 exit;
6 } // Exit if accessed directly.
7
8 use Essential_Addons_Elementor\Classes\Helper;
9 use Essential_Addons_Elementor\Classes\WPDeveloper_Core_Installer;
10
11 class WPDeveloper_Notice {
12 /**
13 * Admin Notice Key
14 *
15 * @var array
16 */
17 const ADMIN_UPDATE_NOTICE_KEY = 'wpdeveloper_notices_seen';
18
19 /**
20 * All Data
21 * @var array
22 */
23 private $data = array();
24 private $properties = array(
25 'links', 'message', 'thumbnail',
26 );
27 private $methods = array(
28 'message', 'thumbnail', 'classes'
29 );
30 /**
31 * cne_day == current_notice_end_day
32 *
33 * @var integer
34 */
35 public $cne_time = '2 day';
36 public $maybe_later_time = '7 day';
37 public $finish_time = [];
38 /**
39 * Plugin Name
40 *
41 * @var string
42 */
43 private $plugin_name;
44 /**
45 * Plugin File Name
46 * @var string
47 */
48 private $plugin_file;
49 /**
50 * First Install Version Of The Plugin
51 *
52 * @var string
53 */
54 private $version;
55 /**
56 * Saved Data in DB
57 * @var array
58 */
59 private $options_data;
60 /**
61 * Current Timestamp
62 * @var integer
63 */
64 public $timestamp;
65 /**
66 * Primary Notice Action
67 *
68 * @var string
69 */
70 private $do_notice_action;
71 /**
72 * Default Options Set
73 *
74 * @var array
75 */
76 public $options_args = array(
77
78 );
79 /**
80 * Notice ID for users.
81 * @var string
82 */
83 private $notice_id;
84 /**
85 * Upsale Notice Arguments
86 * @var array
87 */
88 public $upsale_args;
89 /**
90 * Revoke this function when the object is created.
91 *
92 * @param string $plugin_name
93 * @param string $version
94 */
95 public function __construct( $plugin_file = '', $version = '' ) {
96 $this->plugin_file = $plugin_file;
97 $this->plugin_name = basename( $plugin_file, '.php' );
98 $this->version = $version;
99 $this->timestamp = intval( current_time( 'timestamp' ) );
100 $this->notice_id = 'wpdeveloper_notice_' . str_replace( '.', '_', $this->version );
101
102 $this->do_notice_action = 'wpdeveloper_notices_for_' . $this->plugin_name;
103
104 new WPDeveloper_Core_Installer( $this->plugin_name );
105 }
106 /**
107 * Initiate The Plugin
108 * @return void
109 */
110 public function init(){
111 $this->migration();
112 add_action( 'init', array( $this, 'first_install_track') );
113 add_action( 'deactivate_' . $this->plugin_file, array( $this, 'first_install_end' ) );
114 add_action( 'init', array( $this, 'hooks' ) );
115 }
116 public function migration(){
117 $user_notices = $this->get_user_notices();
118 if( \version_compare( get_option( 'eael_version', false ), '3.7.2', '==' ) && ! get_option( 'eael_notice_migration', false ) ) {
119 if( is_array( $user_notices ) ) {
120 array_walk( $user_notices, function( $value, $key ){
121 array_walk( $value, function( $v, $k ){
122 array_walk( $v, function( $vv, $kk ){
123 update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $vv, true );
124 } );
125 } );
126 } );
127 }
128 update_option( 'eael_notice_migration', true );
129 }
130 }
131 /**
132 * All Hooks
133 * @return void
134 */
135 public function hooks(){
136 add_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name, array( $this, 'clicked' ) );
137 add_action( 'wp_ajax_wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'upsale_notice_dissmiss' ) );
138 add_action( 'wp_ajax_wpdeveloper_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'notice_dissmiss' ) );
139 add_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name, array( $this, 'before' ) );
140 add_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
141 add_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name, array( $this, 'before_upsale' ) );
142 add_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
143 add_action( $this->do_notice_action, array( $this, 'content' ) );
144 // if( current_user_can( 'install_plugins' ) ) {
145 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
146 if( isset( $_GET['plugin'] ) && sanitize_text_field( wp_unslash( $_GET['plugin'] ) ) == $this->plugin_name ) {
147 do_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name );
148 /**
149 * Redirect User To the Current URL, but without set query arguments.
150 */
151 wp_safe_redirect( $this->redirect_to() );
152 }
153 $return_notice = $this->next_notice();
154 $current_notice = current( $return_notice );
155 $next_notice = next( $return_notice );
156
157 $deserve_notice = $this->deserve_notice( $current_notice );
158 $options_data = $this->get_options_data();
159 $user_notices = $this->get_user_notices();
160
161 $notice_time = isset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] )
162 ? $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] : $this->timestamp;
163 $next_notice_time = $next_notice ? $options_data[ $this->plugin_name ]['notice_will_show'][ $next_notice ] : $this->timestamp;
164 $current_notice_end = $this->makeTime( $notice_time, $this->cne_time );
165
166 if( ! $deserve_notice ) {
167 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
168 $this->update_options_data( $options_data[ $this->plugin_name ] );
169 }
170
171 if( $deserve_notice ) {
172 /**
173 * TODO: automatic maybe later setup with time.
174 */
175 if( ( $this->timestamp >= $current_notice_end ) || ( $this->timestamp > $next_notice_time ) ) {
176 $this->maybe_later( $current_notice );
177 $notice_time = false;
178 }
179
180 if( isset( $this->finish_time[ $current_notice ] ) ) {
181 if( $this->timestamp >= strtotime( $this->finish_time[ $current_notice ] ) ) {
182 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
183 $this->update_options_data( $options_data[ $this->plugin_name ] );
184 $notice_time = false;
185 }
186 }
187
188 if( $notice_time != false ) {
189 if( $notice_time <= $this->timestamp ) {
190 if( $current_notice === 'upsale' ) {
191 $upsale_args = $this->get_upsale_args();
192 if( empty( $upsale_args ) ) {
193 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
194 $this->update_options_data( $options_data[ $this->plugin_name ] );
195 } else {
196 /**
197 * For Upsale Remove
198 * if the plugin is activated.
199 */
200 if( isset( $upsale_args['condition'], $upsale_args['condition']['by'] ) ) {
201 switch( $upsale_args['condition']['by'] ) {
202 case 'class' :
203 if( isset( $upsale_args['condition']['class'] ) && class_exists( $upsale_args['condition']['class'] ) ) {
204 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
205 $this->update_options_data( $options_data[ $this->plugin_name ] );
206 return;
207 }
208 break;
209 case 'function' :
210 if( isset( $upsale_args['condition']['function'] ) && function_exists( $upsale_args['condition']['function'] ) ) {
211 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
212 $this->update_options_data( $options_data[ $this->plugin_name ] );
213 return;
214 }
215 break;
216 }
217 }
218 if ( ! function_exists( 'get_plugins' ) ) {
219 include ABSPATH . '/wp-admin/includes/plugin.php';
220 }
221 $plugins = get_plugins();
222 $pkey = $upsale_args['slug'] . '/' . $upsale_args['file'];
223 if( isset( $plugins[ $pkey ] ) ) {
224 $this->update( $current_notice );
225 return;
226 }
227 add_action( 'admin_notices', array( $this, 'upsale_notice' ) );
228 add_action( 'eael_admin_notices', array( $this, 'upsale_notice' ) );
229 }
230 } else {
231 if( $this->is_ok( 'message', $current_notice ) || $current_notice === 'opt_in' ) {
232 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
233 add_action( 'eael_admin_notices', array( $this, 'admin_notices' ) );
234 }
235 }
236 }
237 }
238 }
239 // }
240 }
241 /**
242 * Make time using timestamp and a string like 2 Hour, 2 Day, 30 Minutes, 1 Week, 1 year
243 * @param integer $current
244 * @param string $time
245 * @return integer
246 */
247 public function makeTime( $current, $time ) {
248 return intval( strtotime( gmdate( 'Y-m-d h:i:s', intval( $current ) ) . " +$time" ) );
249 }
250 /**
251 * Automatice Maybe Later.
252 * @param string $notice
253 * @return void
254 */
255 private function maybe_later( $notice ){
256 if( empty( $notice ) ) {
257 return;
258 }
259 $options_data = $this->get_options_data();
260 $options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] = $this->makeTime( $this->timestamp, $this->maybe_later_time );
261 $this->update_options_data( $options_data[ $this->plugin_name ] );
262 }
263 /**
264 * When links are clicked, this function will invoked.
265 * @return void
266 */
267 public function clicked(){
268 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
269 if( isset( $_GET['plugin'] ) ) {
270 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
271 $plugin = sanitize_text_field( wp_unslash( $_GET['plugin'] ) );
272 if( $plugin === $this->plugin_name ) {
273 $options_data = $this->get_options_data();
274 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
275 $clicked_from = current( $this->next_notice() );
276 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
277 if( isset( $_GET['plugin_action'] ) ) {
278 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
279 $plugin_action = sanitize_text_field( wp_unslash( $_GET['plugin_action'] ) );
280 }
281 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
282 if( isset( $_GET['dismiss'] ) ) {
283 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
284 $dismiss = sanitize_text_field( wp_unslash( $_GET['dismiss'] ) );
285 }
286 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
287 if( isset( $_GET['later'] ) ) {
288 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
289 $later = sanitize_text_field( wp_unslash( $_GET['later'] ) );
290 }
291
292 $later_time = '';
293
294 switch( $clicked_from ) {
295
296 case 'opt_in' :
297 $dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
298 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
299 break;
300
301 case 'first_install' :
302 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
303 break;
304
305 case 'update' :
306 $dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
307 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
308 break;
309 // case 'update_400k' :
310 // $dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
311 // $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
312 // break;
313 case 'review' :
314 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
315 break;
316 case 'upsale' :
317 $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
318 break;
319 }
320
321 if( isset( $later ) && $later == true ) {
322 $options_data[ $this->plugin_name ]['notice_will_show'][ $clicked_from ] = $later_time;
323 }
324 if( isset( $dismiss ) && $dismiss == true ) {
325 update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $clicked_from, true );
326 $this->update( $clicked_from );
327 }
328 $this->update_options_data( $options_data[ $this->plugin_name ] );
329 }
330 }
331 }
332 /**
333 * For Redirecting Current Page without Arguments!
334 *
335 * @return void
336 */
337 private function redirect_to(){
338 $request_uri = !empty( $_SERVER['REQUEST_URI'] ) ? wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH ) : '';
339 $query_string = !empty( $_SERVER['REQUEST_URI'] ) ? wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_QUERY ) : '';
340 wp_parse_str( $query_string, $current_url );
341
342 $unset_array = array( 'dismiss', 'plugin', '_wpnonce', 'later', 'plugin_action', 'marketing_optin' );
343
344 foreach( $unset_array as $value ) {
345 if( isset( $current_url[ $value ] ) ) {
346 unset( $current_url[ $value ] );
347 }
348 }
349
350 $current_url = http_build_query($current_url);
351 $redirect_url = $request_uri . '?' . $current_url;
352 return $redirect_url;
353 }
354 /**
355 * Before Notice
356 * @return void
357 */
358 public function before(){
359 $current_notice = current( $this->next_notice() );
360 $classes = 'notice notice-info put-dismiss-notice';
361 if( isset( $this->data['classes'] ) ) {
362 if( isset( $this->data['classes'][ $current_notice ] ) ) {
363 $classes = $this->data['classes'][ $current_notice ];
364 }
365 }
366
367 if( $this->has_thumbnail( $current_notice ) ) {
368 $classes .= 'notice-has-thumbnail';
369 }
370
371 echo '<div class="'. esc_attr( $classes ) .' wpdeveloper-'. esc_attr( $current_notice ) .'-notice" data-notice="'. esc_attr( $current_notice ) .'">';
372 }
373 /**
374 * After Notice
375 * @return void
376 */
377 public function after(){
378 echo '</div>';
379 }
380 /**
381 * Content generation & Hooks Funciton.
382 * @return void
383 */
384 public function content(){
385 $options_data = $this->get_options_data();
386 $notice = current( $this->next_notice() );
387
388 switch( $notice ) {
389 case 'opt_in' :
390 do_action('wpdeveloper_optin_notice_for_' . $this->plugin_name );
391 break;
392 case 'first_install' :
393 if( $options_data[ $this->plugin_name ]['first_install'] !== 'deactivated' ) {
394 do_action( 'wpdeveloper_first_install_notice_for_' . $this->plugin_name );
395 $this->get_thumbnail( 'first_install' );
396 $this->get_message( 'first_install' );
397 }
398 break;
399 case 'update' :
400 do_action( 'wpdeveloper_update_notice_for_' . $this->plugin_name );
401 $this->dismiss_button_scripts();
402 $this->get_thumbnail( 'update' );
403 $this->get_message( 'update' );
404 break;
405 // case 'update_400k' :
406 // do_action( 'wpdeveloper_update_notice_for_' . $this->plugin_name );
407 // $this->dismiss_button_scripts();
408 // $this->get_thumbnail( 'update_400k' );
409 // $this->get_message( 'update_400k' );
410 // break;
411 case 'review' :
412 do_action( 'wpdeveloper_review_notice_for_' . $this->plugin_name );
413 $this->get_thumbnail( 'review' );
414 $this->get_message( 'review' );
415 break;
416 }
417 }
418 /**
419 * Before Upsale Notice
420 * @return void
421 */
422 public function before_upsale(){
423 $classes = '';
424 if( $this->has_thumbnail('upsale') ) {
425 $classes = 'notice-has-thumbnail';
426 }
427 echo '<div class="error notice is-dismissible wpdeveloper-upsale-notice '. esc_attr( $classes ) .'">';
428 }
429 /**
430 * Upsale Notice
431 */
432 public function upsale_notice(){
433 do_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name );
434 do_action('wpdeveloper_upsale_notice_for_' . $this->plugin_name);
435 $this->get_thumbnail( 'upsale' );
436 $this->get_message( 'upsale' );
437 do_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name );
438 $this->upsale_button_script();
439 }
440 /**
441 * Get upsale arguments.
442 * @return void
443 */
444 private function get_upsale_args(){
445 return ( empty( $this->upsale_args ) ) ? array() : $this->upsale_args;
446 }
447 /**
448 * This function is responsible for making the button visible to the upsale notice.
449 */
450 private function upsale_button(){
451 $upsale_args = $this->get_upsale_args();
452 $plugin_slug = ( isset( $upsale_args['slug'] )) ? $upsale_args['slug'] : '' ;
453 $btn_text = ( isset( $upsale_args['btn_text'] )) ? $upsale_args['btn_text'] : __( 'Install Now!', 'essential-addons-for-elementor-lite' ) ;
454 if( empty( $plugin_slug ) ) {
455 return;
456 }
457 echo '<button data-slug="'. esc_attr( $plugin_slug ) .'" id="plugin-install-core-'. esc_attr( $this->plugin_name ) .'" class="button button-primary">'. wp_kses( $btn_text, Helper::eael_allowed_tags() ) .'</button>';
458 }
459 /**
460 * This methods is responsible for get notice image.
461 *
462 * @param string $msg_for
463 * @return void
464 */
465 protected function get_thumbnail( $msg_for ){
466 $output = '';
467 if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
468 $output = '<div class="wpdeveloper-notice-thumbnail">';
469 $output .= '<img src="'. esc_url( $this->data['thumbnail'][ $msg_for ] ) .'" alt="">';
470 $output .= '</div>';
471 }
472 echo wp_kses_post( $output );
473
474 }
475 /**
476 * Has Thumbnail Check
477 *
478 * @param string $msg_for
479 * @return boolean
480 */
481 protected function has_thumbnail( $msg_for = '' ){
482 if( empty( $msg_for ) ) {
483 return false;
484 }
485 if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
486 return true;
487 }
488 return false;
489 }
490 /**
491 * This method is responsible for get messages.
492 *
493 * @param string $msg_for
494 * @return void
495 */
496 protected function get_message( $msg_for ){
497 if( isset( $this->data['message'] ) && isset( $this->data['message'][ $msg_for ] ) ) {
498 echo '<div class="wpdeveloper-notice-message">';
499 echo wp_kses( $this->data['message'][ $msg_for ], Helper::eael_allowed_tags() );
500 if( $msg_for === 'upsale' ) {
501 $this->upsale_button();
502 }
503 $this->dismissible_notice( $msg_for );
504 echo '</div>';
505 }
506 }
507 /**
508 * Detect which notice will show @ next.
509 * @return array
510 */
511 protected function next_notice() {
512 $options_data = $this->get_options_data();
513 if ( ! $options_data ) {
514 $args = $this->get_args();
515 $return_notice = $args['notice_will_show'];
516 } else {
517 $return_notice = $options_data[ $this->plugin_name ]['notice_will_show'];
518 }
519
520 if ( is_array( $return_notice ) ) {
521 $return_notice = array_flip( $return_notice );
522 ksort( $return_notice );
523 }
524
525 return (array) $return_notice;
526 }
527 /**
528 * Which notice is deserve to show in next slot.
529 * @param string $notice
530 * @return boolean
531 */
532 private function deserve_notice( $notice ) {
533 $notices = $this->get_user_notices();
534 if( $notice === false ) {
535 return false;
536 }
537 if( empty( $notices ) ) {
538 return true;
539 } else {
540 if( isset( $notices[ $this->notice_id ] ) && isset( $notices[ $this->notice_id ][ $this->plugin_name ] ) ) {
541 if( in_array( $notice, $notices[ $this->notice_id ][ $this->plugin_name ] ) ) {
542 return false;
543 } else {
544 return true;
545 }
546 } else {
547 return true;
548 }
549 }
550 }
551 /**
552 * This is the main methods for generate the notice.
553 * @return void
554 */
555 public function admin_notices(){
556 $current_notice = current( $this->next_notice() );
557 if( get_user_meta( get_current_user_id(), $this->plugin_name . '_' . $current_notice, true ) ) {
558 return;
559 }
560 if( $current_notice == 'opt_in' ) {
561 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
562 do_action( $this->do_notice_action );
563 return;
564 }
565 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
566 do_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name );
567 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
568 do_action( $this->do_notice_action );
569 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
570 do_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name );
571 }
572 /**
573 * This method is responsible for all dismissible links generation.
574 * @param string $links_for
575 * @return void
576 */
577 public function dismissible_notice( $links_for = '' ){
578 if( empty( $links_for ) ) {
579 return;
580 }
581 $links = isset( $this->data['links'][ $links_for ] ) ? $this->data['links'][ $links_for ] : false;
582 if( $links ) :
583 $output = '<ul class="wpdeveloper-notice-link">';
584 foreach( $links as $key => $link_value ) {
585 if( ! empty( $link_value['label'] ) ) {
586 $output .= '<li>';
587 if( isset( $link_value['link'] ) ) {
588 $link = $link_value['link'];
589 $target = isset( $link_value['target'] ) ? 'target="'. esc_attr( $link_value['target'] ) .'"' : '';
590 if( isset( $link_value['data_args'] ) && is_array( $link_value['data_args'] ) ) {
591 $data_args = [];
592 foreach( $link_value['data_args'] as $key => $args_value ) {
593 $data_args[ $key ] = $args_value;
594 }
595 $data_args[ 'plugin' ] = $this->plugin_name;
596 $normal_link = add_query_arg( $data_args, $link );
597 $link = wp_nonce_url( $normal_link, 'wpdeveloper-nonce' );
598 }
599 $class = '';
600 if( isset( $link_value['link_class'] ) ) {
601 $class = 'class="' . sanitize_html_class( implode( ' ', $link_value['link_class'] ) ) . '"';
602 }
603 $output .= '<a '. $class .' href="'. esc_url( $link ) .'" '. $target .'>';
604 }
605 if( isset( $link_value['icon_class'] ) ) {
606 $output .= '<span class="'. esc_attr( $link_value['icon_class'] ) .'"></span>';
607 }
608 if( isset( $link_value['icon_img'] ) ) {
609 $output .= '<img src="'. esc_url( $link_value['icon_img'] ) .'" alt="" />';
610 }
611 $output .= $link_value['label'];
612 if( isset( $link_value['link'] ) ) {
613 $output .= '</a>';
614 }
615 $output .= '</li>';
616 }
617 }
618 $output .= '</ul>';
619
620 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
621 printf( '%1$s', $output );
622 endif;
623 }
624 /**
625 * First Installation Track
626 * @return void
627 */
628 public function first_install_track( $args = array() ){
629 if( ! current_user_can( 'manage_options' ) ) {
630 return;
631 }
632 if( empty( $args ) ) {
633 $args = array(
634 'time' => $this->timestamp,
635 'version' => $this->version,
636 );
637 }
638 $options_data = $this->get_options_data();
639 $args = wp_parse_args( $args, $this->get_args() );
640 if( ! isset( $options_data[ $this->plugin_name ] )
641 || ( isset( $options_data[ $this->plugin_name ]['version'] ) && version_compare( $options_data[ $this->plugin_name ]['version'], $this->version, '!=' ) ) ) {
642 $this->update_options_data( $args );
643 }
644 }
645 /**
646 * First Installation Deactive Track
647 *
648 * @return void
649 */
650 public function first_install_end(){
651 // $args = array(
652 // 'first_install' => 'deactivated'
653 // );
654 // $options_data = $this->get_options_data();
655 // if( isset( $options_data[ $this->plugin_name ] ) ) {
656 // $args = wp_parse_args( $args, $options_data[ $this->plugin_name ] );
657 // $this->update_options_data( $args );
658 // }
659 delete_option( 'wpdeveloper_plugins_data' );
660 }
661 /**
662 * Get all options from database!
663 * @return void
664 */
665 protected function get_options_data( $key = '' ) {
666 $options_data = get_option( 'wpdeveloper_plugins_data', [] );
667 if ( empty( $key ) ) {
668 return $options_data;
669 }
670
671 if ( isset( $options_data[ $this->plugin_name ][ $key ] ) ) {
672 return $options_data[ $this->plugin_name ][ $key ];
673 }
674
675 return [];
676 }
677 /**
678 * This will update the options table for plugins.
679 *
680 * @param mixed $new_data
681 * @param array $args
682 * @return void
683 */
684 protected function update_options_data( $args = array() ){
685 $options_data = $this->get_options_data();
686 $options_data[ $this->plugin_name ] = $args;
687 update_option( 'wpdeveloper_plugins_data', $options_data );
688 }
689 /**
690 * Set properties data, for some selected properties.
691 *
692 * @param string $name
693 * @param mixed $value
694 */
695 public function __set( $name, $value ){
696 if( in_array( $name, $this->properties ) ) {
697 $this->data[ $name ] = $value;
698 }
699 }
700 /**
701 * Invoked when some selected methods are called
702 *
703 * @param string $name
704 * @param array $values
705 * @return void
706 */
707 public function __call( $name, $values ){
708 if( in_array( $name, $this->methods ) ) {
709 $this->data[ $name ][ $values[0] ] = $values[1];
710 }
711 }
712 protected function is_ok( $name, $notice ){
713 if( isset( $this->data[ $name ], $this->data[ $name ][ $notice ] ) ) {
714 return true;
715 }
716 return false;
717 }
718 /**
719 * Get all option arguments.
720 * @param string $key
721 * @return array
722 */
723 private function get_args( $key = '' ){
724 if( empty( $key ) ) {
725 return $this->options_args;
726 }
727
728 if( isset( $this->options_args[ $key ] ) ) {
729 return $this->options_args[ $key ];
730 }
731
732 return false;
733 }
734 /**
735 * Resetting data on update.
736 * @return void
737 */
738 private function set_args_on_update(){
739 $args = $this->get_args();
740 $options_data = $this->get_options_data();
741 $set_data = $options_data[ $this->plugin_name ];
742 $args = wp_parse_args( $set_data, $args );
743 $this->update_options_data( $args );
744 }
745 /**
746 * When upgrade is complete. it will fired.
747 * @param WP_Upgrader $upgrader_object
748 * @param array $options
749 * @return void
750 */
751 public function upgrade_completed( $upgrader_object, $options ) {
752 // If an update has taken place and the updated type is plugins and the plugins element exists
753 if( isset( $options['action'] ) && $options['action'] == 'update' && $options['type'] == 'plugin' ) {
754 if( ! isset( $options['plugin'] ) && isset( $options['plugins'] ) ) {
755 foreach( $options['plugins'] as $plugin ) {
756 if( $plugin == $this->plugin_name ) {
757 $this->set_args_on_update();
758 }
759 }
760 }
761
762 if( isset( $options['plugin'] ) && $options['plugin'] == $this->plugin_name ) {
763 $this->set_args_on_update();
764 }
765 }
766 }
767 /**
768 * This function is responsible for get_user_notices
769 * @return void
770 */
771 private function get_user_notices() {
772 $notices = get_user_meta( get_current_user_id(), self::ADMIN_UPDATE_NOTICE_KEY, true );
773 return ! $notices ? array() : $notices;
774 }
775 /**
776 * This function is responsible for update meta information.
777 *
778 * @param string $notice
779 * @return void
780 */
781 private function update( $notice ){
782 if( empty( $notice ) ) {
783 return;
784 }
785 $options_data = $this->get_options_data();
786 $user_notices = $this->get_user_notices();
787 $user_notices[ $this->notice_id ][ $this->plugin_name ][] = $notice;
788 // Remove the upsale from notice_will_show field in options DB.
789 unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] );
790 $this->update_options_data( $options_data[ $this->plugin_name ] );
791 // Set users meta, not to show again current_version notice.
792 update_user_meta( get_current_user_id(), self::ADMIN_UPDATE_NOTICE_KEY, $user_notices);
793 }
794
795 public function notice_dissmiss(){
796 if( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpdeveloper_notice_dissmiss' ) ) {
797 return;
798 }
799
800 if( ! isset( $_POST['action'] ) || ( $_POST['action'] !== 'wpdeveloper_notice_dissmiss_for_' . $this->plugin_name ) ) {
801 return;
802 }
803
804 $dismiss = isset( $_POST['dismiss'] ) ? sanitize_text_field( wp_unslash( $_POST['dismiss'] ) ) : false;
805 $notice = isset( $_POST['notice'] ) ? sanitize_text_field( wp_unslash( $_POST['notice'] ) ) : false;
806 if( $dismiss ) {
807 $this->update( $notice );
808 update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $notice, true );
809 echo 'success';
810 } else {
811 echo 'failed';
812 }
813 die();
814 }
815
816 /**
817 * This function is responsible for do action when
818 * the dismiss button clicked in upsale notice.
819 */
820 public function upsale_notice_dissmiss(){
821
822 if( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpdeveloper_upsale_notice_dissmiss' ) ) {
823 return;
824 }
825
826 if( ! isset( $_POST['action'] ) || ( $_POST['action'] !== 'wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name ) ) {
827 return;
828 }
829
830 $dismiss = isset( $_POST['dismiss'] ) ? sanitize_text_field( wp_unslash( $_POST['dismiss'] ) ) : false;
831 if( $dismiss ) {
832 $this->update( 'upsale' );
833 echo 'success';
834 } else {
835 echo 'failed';
836 }
837 die();
838 }
839
840 public function dismiss_button_scripts(){
841 ?>
842 <script type="text/javascript">
843 jQuery(document).ready( function($) {
844 var wpdevNotice = $('.notice.is-dismissible');
845 if( wpdevNotice.length > 0 ) {
846 $('body').on('click', 'button.notice-dismiss', function (e) {
847 e.preventDefault();
848 $.ajax({
849 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
850 type: 'post',
851 data: {
852 action: 'wpdeveloper_notice_dissmiss_for_<?php echo esc_html( $this->plugin_name ); ?>',
853 _wpnonce: '<?php
854 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
855 echo wp_create_nonce('wpdeveloper_notice_dissmiss'); ?>',
856 dismiss: true,
857 notice: wpdevNotice.data('notice'),
858 },
859 success: function(response) {
860 $('.notice').hide();
861 console.log('Successfully saved!');
862 },
863 error: function(error) {
864 console.log('Something went wrong!');
865 },
866 complete: function() {
867 console.log('Its Complete.');
868 }
869 });
870 });
871 }
872 } );
873 </script>
874 <?php
875 }
876
877 /**
878 * Upsale Button Script.
879 * When install button is clicked, it will do its own things.
880 * also for dismiss button JS.
881 * @return void
882 */
883 public function upsale_button_script(){
884 $upsale_args = $this->get_upsale_args();
885
886 $plugin_slug = ( isset( $upsale_args['slug'] ) ) ? $upsale_args['slug'] : '';
887 $plugin_file = ( isset( $upsale_args['file'] ) ) ? $upsale_args['file'] : '';
888 $page_slug = ( isset( $upsale_args['page_slug'] ) ) ? $upsale_args['page_slug'] : '';
889
890 ?>
891 <script type="text/javascript">
892 jQuery(document).ready( function($) {
893 <?php if( ! empty( $plugin_slug ) && ! empty( $plugin_file ) ) : ?>
894 $('#plugin-install-core-<?php echo esc_html( $this->plugin_name ); ?>').on('click', function (e) {
895 var self = $(this);
896 e.preventDefault();
897 self.addClass('install-now updating-message');
898 self.text('<?php echo esc_js( 'Installing...' ); ?>');
899
900 $.ajax({
901 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
902 type: 'POST',
903 data: {
904 action: 'wpdeveloper_upsale_core_install_<?php echo esc_html( $this->plugin_name ); ?>',
905 _wpnonce: '<?php
906 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
907 echo wp_create_nonce('wpdeveloper_upsale_core_install_' . esc_html( $this->plugin_name )); ?>',
908 slug : '<?php echo esc_html( $plugin_slug ); ?>',
909 file : '<?php echo esc_html( $plugin_file ); ?>'
910 },
911 success: function(response) {
912 self.text('<?php echo esc_js( 'Installed' ); ?>');
913 <?php if( ! empty( $page_slug ) ) : ?>
914 window.location.href = '<?php echo esc_url( admin_url( "admin.php?page={$page_slug}" ) ); ?>';
915 <?php endif; ?>
916 },
917 error: function(error) {
918 self.removeClass('install-now updating-message');
919 },
920 complete: function() {
921 self.attr('disabled', 'disabled');
922 self.removeClass('install-now updating-message');
923 }
924 });
925 });
926 <?php endif; ?>
927 $('.wpdeveloper-upsale-notice').on('click', 'button.notice-dismiss', function (e) {
928 e.preventDefault();
929 $.ajax({
930 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
931 type: 'post',
932 data: {
933 action: 'wpdeveloper_upsale_notice_dissmiss_for_<?php echo esc_html( $this->plugin_name ); ?>',
934 _wpnonce: '<?php
935 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
936 echo wp_create_nonce('wpdeveloper_upsale_notice_dissmiss'); ?>',
937 dismiss: true
938 },
939 success: function(response) {
940 console.log('Successfully saved!');
941 },
942 error: function(error) {
943 console.log('Something went wrong!');
944 },
945 complete: function() {
946 console.log('Its Complete.');
947 }
948 });
949 });
950 } );
951 </script>
952
953 <?php
954 }
955 }
956