| @@ -1,50 +1,43 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Boxzilla\Admin; |
| 4 | 4 | |
| 5 | -if (! defined('ABSPATH')) { | |
| 6 | - exit; | |
| 7 | -} | |
| 5 | +class Notices { | |
| 8 | 6 | |
| 9 | -class Notices | |
| 10 | -{ | |
| 11 | - /** | |
| 12 | - * @var array | |
| 13 | - */ | |
| 14 | - protected $notices = []; | |
| 15 | 7 | |
| 16 | - /** | |
| 17 | - * Constructor | |
| 18 | - */ | |
| 19 | - public function __construct() | |
| 20 | - { | |
| 21 | - add_action('admin_notices', [ $this, 'action_admin_notices' ], 10, 0); | |
| 22 | - } | |
| 8 | + /** | |
| 9 | + * @var array | |
| 10 | + */ | |
| 11 | + protected $notices = array(); | |
| 23 | 12 | |
| 24 | - /** | |
| 25 | - * @param $message | |
| 26 | - * @param $type | |
| 27 | - * | |
| 28 | - * @return $this | |
| 29 | - */ | |
| 30 | - public function add($message, $type = 'updated') | |
| 31 | - { | |
| 32 | - $this->notices[] = [ | |
| 33 | - 'message' => $message, | |
| 34 | - 'type' => $type, | |
| 35 | - ]; | |
| 13 | + /** | |
| 14 | + * Constructor | |
| 15 | + */ | |
| 16 | + public function __construct() { | |
| 17 | + add_action( 'admin_notices', array( $this, 'show' ) ); | |
| 18 | + } | |
| 36 | 19 | |
| 37 | - return $this; | |
| 38 | - } | |
| 20 | + /** | |
| 21 | + * @param $message | |
| 22 | + * @param $type | |
| 23 | + * | |
| 24 | + * @return $this | |
| 25 | + */ | |
| 26 | + public function add( $message, $type = 'updated' ) { | |
| 27 | + $this->notices[] = array( | |
| 28 | + 'message' => $message, | |
| 29 | + 'type' => $type, | |
| 30 | + ); | |
| 39 | 31 | |
| 40 | - /** | |
| 41 | - * Output the registered notices | |
| 42 | - */ | |
| 43 | - public function admin_notices(): void | |
| 44 | - { | |
| 45 | - $allowed_html = [ 'strong' => [], 'em' => [], 'a' => [ 'href' => [] ] ]; | |
| 46 | - foreach ($this->notices as $notice) { | |
| 47 | - echo "<div class=\"notice notice-", esc_attr($notice['type']), "><p>", wp_kses($notice['message'], $allowed_html), "</p></div>"; | |
| 48 | - } | |
| 49 | - } | |
| 32 | + return $this; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Output the registered notices | |
| 37 | + */ | |
| 38 | + public function show() { | |
| 39 | + foreach ( $this->notices as $notice ) { | |
| 40 | + echo sprintf( '<div class="notice notice-%s"><p>%s</p></div>', $notice['type'], $notice['message'] ); | |
| 41 | + } | |
| 42 | + } | |
| 50 | 43 | } |