PluginProbe
Orderable – Restaurant & Food Ordering System / 1.14.0
Orderable – Restaurant & Food Ordering System v1.14.0
0.1.4 0.1.5 0.2.0 1.0.0 1.1.0 1.1.1 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.19.1 1.19.2 1.2.0 1.20.0 1.20.1 All 44 releases
orderable / inc / class-admin-notices.php

class-admin-notices.php in Orderable – Restaurant & Food Ordering System 1.14.0, at inc/class-admin-notices.php

112 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Notices.
4 *
5 * @package Orderable/Classes
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Admin Notices class.
12 */
13 class Orderable_Admin_Notices {
14 /**
15 * Run.
16 */
17 public static function run() {
18 if ( ! is_admin() ) {
19 return;
20 }
21
22 add_action( 'admin_notices', array( __CLASS__, 'display_notices' ) );
23 add_action( 'admin_init', array( __CLASS__, 'dismiss' ) );
24 }
25
26 /**
27 * Dismiss notices.
28 */
29 public static function dismiss() {
30 // Permissions check.
31 if ( ! current_user_can( 'install_plugins' ) ) {
32 return;
33 }
34
35 // phpcs:ignore WordPress.Security.NonceVerification
36 $action = empty( $_GET['orderable_action'] ) ? '' : sanitize_text_field( wp_unslash( $_GET['orderable_action'] ) );
37
38 // Not our notices, bail.
39 if ( 'dismiss_notice' !== $action ) {
40 return;
41 }
42
43 // Get notice.
44 $name = empty( $_GET['orderable_notice'] ) ? '' : sanitize_text_field( wp_unslash( $_GET['orderable_notice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
45
46 if ( ! $name ) {
47 return;
48 }
49
50 // Notice is dismissed.
51 update_option( 'orderable_dismissed_notice_' . $name, 1 );
52 }
53
54 /**
55 * Check if notice is dismissed.
56 *
57 * @param string $name
58 *
59 * @return bool
60 */
61 public static function is_dismissed( $name ) {
62 return (bool) get_option( 'orderable_dismissed_notice_' . $name, false );
63 }
64
65 /**
66 * Display notices if they exist.
67 */
68 public static function display_notices() {
69 $notices = apply_filters( 'orderable_admin_notices', array() );
70
71 if ( empty( $notices ) ) {
72 return;
73 }
74
75 $default_options = array(
76 'name' => null,
77 'title' => '',
78 'description' => '',
79 'dismissable' => true,
80 );
81
82 foreach ( $notices as $notice ) {
83 $notice = wp_parse_args( $notice, $default_options );
84
85 if ( is_null( $notice['name'] ) || self::is_dismissed( $notice['name'] ) ) {
86 continue;
87 } ?>
88 <div class="notice notice--orderable" style="border-left-color: #7031F5;">
89 <p><strong><?php echo wp_kses_post( $notice['title'] ); ?></strong></p>
90 <p><?php echo wp_kses_post( $notice['description'] ); ?></p>
91 <?php if ( $notice['dismissable'] ) { ?>
92 <p>
93 <a href="
94 <?php
95 echo esc_url(
96 add_query_arg(
97 array(
98 'orderable_action' => 'dismiss_notice',
99 'orderable_notice' => $notice['name'],
100 )
101 )
102 );
103 ?>
104 "><?php _e( 'Dismiss Notice', 'orderable' ); ?></a>
105 </p>
106 <?php } ?>
107 </div>
108 <?php
109 }
110 }
111 }
112