PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / trunk
WCPOS – Point of Sale (POS) plugin for WooCommerce vtrunk
1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 1.9.12 1.9.11 1.9.10 All 159 releases
woocommerce-pos / includes / Admin / Notices.php

Notices.php in WCPOS – Point of Sale (POS) plugin for WooCommerce trunk, at includes/Admin/Notices.php

80 lines 1.6 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 * - add notices via static method or filter.
5 *
6 * @author Paul Kilmurray <paul@kilbot.com>
7 *
8 * @see http://wcpos.com
9 * @package WCPOS\WooCommercePOS
10 */
11
12 namespace WCPOS\WooCommercePOS\Admin;
13
14 /**
15 * Notices class.
16 */
17 class Notices {
18 /**
19 * Stored notices.
20 *
21 * @var array
22 */
23 private static $notices = array();
24
25 /**
26 * Constructor.
27 */
28 public function __construct() {
29 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
30 }
31
32 /**
33 * Add a message for display.
34 *
35 * @param string $message The notice message.
36 * @param string $type The notice type.
37 * @param bool $dismissable Whether the notice is dismissable.
38 */
39 public static function add( $message = '', $type = 'error', $dismissable = true ): void {
40 self::$notices[] = array(
41 'type' => $type,
42 'message' => $message,
43 'dismissable' => $dismissable,
44 );
45 }
46
47 /**
48 * Display the admin notices.
49 */
50 public function admin_notices(): void {
51 /**
52 * Filters the POS admin notices.
53 *
54 * @since 1.0.0
55 *
56 * @param array $notices
57 *
58 * @return array $notices
59 *
60 * @hook woocommerce_pos_admin_notices
61 */
62 $notices = apply_filters( 'woocommerce_pos_admin_notices', self::$notices );
63 if ( empty( $notices ) ) {
64 return;
65 }
66
67 foreach ( $notices as $notice ) {
68 $classes = 'notice notice-' . $notice['type'];
69 if ( $notice['dismissable'] ) {
70 $classes .= ' is-dismissable';
71 }
72 if ( $notice['message'] ) {
73 echo '<div class="' . esc_attr( $classes ) . '"><p>' .
74 wp_kses( $notice['message'], wp_kses_allowed_html( 'post' ) ) .
75 '</p></div>';
76 }
77 }
78 }
79 }
80