PluginProbe
GDPRess | Eliminate external requests to increase GDPR compliance / trunk
GDPRess | Eliminate external requests to increase GDPR compliance vtrunk
trunk 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1
gdpr-press / src / Admin / Notice.php

Notice.php in GDPRess | Eliminate external requests to increase GDPR compliance trunk, at src/Admin/Notice.php

63 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package GDPRess
4 * @author Daan van den Bergh
5 * https://daan.dev
6 */
7
8 namespace GDPRess\Admin;
9
10 class Notice {
11
12 const GDPRESS_ADMIN_NOTICE_TRANSIENT = 'gdpress_admin_notice';
13
14 const GDPRESS_ADMIN_NOTICE_EXPIRATION = 60;
15
16 /** @var array $notices */
17 public static $notices = [];
18
19 /**
20 * Prints notice (if any)
21 */
22 public static function print_notices() {
23 $admin_notices = get_transient( self::GDPRESS_ADMIN_NOTICE_TRANSIENT );
24
25 if ( is_array( $admin_notices ) ) {
26 $current_screen = get_current_screen();
27
28 foreach ( $admin_notices as $screen => $notice ) {
29 if ( $current_screen->id != $screen && $screen != 'all' ) {
30 continue;
31 }
32
33 foreach ( $notice as $type => $message ) {
34 ?>
35 <div id="message" class="notice notice-<?php echo esc_attr( $type ); ?> is-dismissible">
36 <?php foreach ( $message as $line ) : ?>
37 <p><strong><?php echo wp_kses_post( $line ); ?></strong></p>
38 <?php endforeach; ?>
39 </div>
40 <?php
41 }
42 }
43 }
44
45 delete_transient( self::GDPRESS_ADMIN_NOTICE_TRANSIENT );
46 }
47
48 /**
49 * @param $message
50 * @param bool $die
51 * @param string $type
52 * @param int $code
53 * @param string $screen_id
54 * @param string $id
55 */
56 public static function set_notice( $message, $type = 'success', $screen_id = 'all', $id = '' ) {
57 self::$notices = get_transient( self::GDPRESS_ADMIN_NOTICE_TRANSIENT );
58 self::$notices[ $screen_id ][ $type ][ $id ] = $message;
59
60 set_transient( self::GDPRESS_ADMIN_NOTICE_TRANSIENT, self::$notices, self::GDPRESS_ADMIN_NOTICE_EXPIRATION );
61 }
62 }
63