PluginProbe
WANotifier for Forms and Actions / 2.7.13
WANotifier for Forms and Actions v2.7.13
3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 1.0.3 All 66 releases
notifier / includes / classes / class-notifier-admin-notices.php

class-notifier-admin-notices.php in WANotifier for Forms and Actions 2.7.13, at includes/classes/class-notifier-admin-notices.php

82 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin notices class
4 *
5 * @package Wa_Notifier
6 */
7 class Notifier_Admin_Notices {
8
9 public $notices = array();
10
11 /**
12 * Notifier Constructor.
13 */
14 public function __construct( $notices, $transient = false, $user_id = 0 ) {
15 if ( $transient ) {
16 if(0 == $user_id){
17 $user_id = get_current_user_id();
18 }
19 set_transient( 'notifier_notice_' . $user_id, $notices, 60 );
20 } else {
21 $this->notices = $notices;
22 add_action('admin_notices', array( $this, 'show_normal_notices'));
23 }
24 }
25
26 /**
27 * Init
28 */
29 public static function init() {
30 if(!is_admin()){
31 return;
32 }
33 $user_id = get_current_user_id();
34 $transient_notices = get_transient( 'notifier_notice_' . $user_id );
35 if ( isset($transient_notices) ) {
36 add_action('admin_notices', array( __CLASS__, 'show_transient_notices'));
37 }
38 }
39
40 /**
41 * Show normal notices
42 */
43 public function show_normal_notices() {
44 if ( empty($this->notices) ) {
45 return;
46 }
47 $notices = $this->notices;
48 self::show_notices($notices);
49 }
50
51 /**
52 * Show transient notices
53 */
54 public static function show_transient_notices() {
55 $user_id = get_current_user_id();
56 $transient_notices = get_transient( 'notifier_notice_' . $user_id );
57 if ( $transient_notices ) {
58 $notices = $transient_notices;
59 delete_transient( 'notifier_notice_' . $user_id );
60 self::show_notices($notices);
61 }
62 }
63
64 /**
65 * Show notices
66 */
67 public static function show_notices( $notices ) {
68 if ( empty($notices) ) {
69 return;
70 }
71
72 foreach ( $notices as $notice ) {
73 ?>
74 <div class="notifier-notice notice notice-<?php echo esc_attr( $notice['type'] ); ?> is-dismissible">
75 <p><?php echo wp_kses_post($notice['message']); ?></p>
76 </div>
77 <?php
78 }
79 }
80
81 }
82