PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.4
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / assets / lib / class_notices.php

class_notices.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.4, at assets/lib/class_notices.php

64 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that adds a misc notice
4 *
5 * @since v.2.0
6 *
7 * @return void
8 */
9 class WPPB_Add_General_Notices{
10 public $notificationId = '';
11 public $notificationMessage = '';
12 public $notificationClass = '';
13 public $startDate = '';
14 public $endDate = '';
15
16 function __construct( $notificationId, $notificationMessage, $notificationClass = 'updated' , $startDate = '', $endDate = '' ){
17 $this->notificationId = $notificationId;
18 $this->notificationMessage = $notificationMessage;
19 $this->notificationClass = $notificationClass;
20
21 if( !empty( $startDate ) && time() < strtotime( $startDate ) )
22 return;
23
24 if( !empty( $endDate ) && time() > strtotime( $endDate ) )
25 return;
26
27 add_action( 'admin_notices', array( $this, 'add_admin_notice' ) );
28 add_action( 'admin_init', array( $this, 'dismiss_notification' ) );
29 }
30
31
32 // Display a notice that can be dismissed in case the serial number is inactive
33 function add_admin_notice() {
34 global $current_user ;
35 global $pagenow;
36
37 $user_id = $current_user->ID;
38 do_action( $this->notificationId.'_before_notification_displayed', $current_user, $pagenow );
39
40 if ( current_user_can( 'manage_options' ) ){
41 // Check that the user hasn't already clicked to ignore the message
42 if ( ! get_user_meta($user_id, $this->notificationId.'_dismiss_notification' ) ) {
43 echo $finalMessage = apply_filters($this->notificationId.'_notification_message','<div class="'. $this->notificationClass .'" >'.$this->notificationMessage.'</div>', $this->notificationMessage);
44 }
45 do_action( $this->notificationId.'_notification_displayed', $current_user, $pagenow );
46 }
47 do_action( $this->notificationId.'_after_notification_displayed', $current_user, $pagenow );
48 }
49
50 function dismiss_notification() {
51 global $current_user;
52
53 $user_id = $current_user->ID;
54
55 do_action( $this->notificationId.'_before_notification_dismissed', $current_user );
56
57 // If user clicks to ignore the notice, add that to their user meta
58 if ( isset( $_GET[$this->notificationId.'_dismiss_notification']) && '0' == $_GET[$this->notificationId.'_dismiss_notification'] )
59 add_user_meta( $user_id, $this->notificationId.'_dismiss_notification', 'true', true );
60
61 do_action( $this->notificationId.'_after_notification_dismissed', $current_user );
62 }
63 }
64 ?>