PluginProbe
WANotifier for Forms and Actions / 3.1.1
WANotifier for Forms and Actions v3.1.1
3.1.1 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 All 67 releases
notifier / includes / classes / class-notifier-admin-notices.php

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

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