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