PluginProbe
WANotifier for Forms and Actions / 2.2.0
WANotifier for Forms and Actions v2.2.0
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.2.0, at includes/classes/class-notifier-admin-notices.php

79 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 $user_id = get_current_user_id();
31 $transient_notices = get_transient( 'notifier_notice_' . $user_id );
32 if ( isset($transient_notices) ) {
33 add_action('admin_notices', array( __CLASS__, 'show_transient_notices'));
34 }
35 }
36
37 /**
38 * Show normal notices
39 */
40 public function show_normal_notices() {
41 if ( empty($this->notices) ) {
42 return;
43 }
44 $notices = $this->notices;
45 self::show_notices($notices);
46 }
47
48 /**
49 * Show transient notices
50 */
51 public static function show_transient_notices() {
52 $user_id = get_current_user_id();
53 $transient_notices = get_transient( 'notifier_notice_' . $user_id );
54 if ( $transient_notices ) {
55 $notices = $transient_notices;
56 delete_transient( 'notifier_notice_' . $user_id );
57 self::show_notices($notices);
58 }
59 }
60
61 /**
62 * Show notices
63 */
64 public static function show_notices( $notices ) {
65 if ( empty($notices) ) {
66 return;
67 }
68
69 foreach ( $notices as $notice ) {
70 ?>
71 <div class="notifier-notice notice notice-<?php echo esc_attr( $notice['type'] ); ?> is-dismissible">
72 <p><?php echo wp_kses_post($notice['message']); ?></p>
73 </div>
74 <?php
75 }
76 }
77
78 }
79