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