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