| 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 |
add_action( 'admin_notices', array( $this, 'show' ) ); |
| 18 |
} |
| 19 |
|
| 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 |
); |
| 31 |
|
| 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 |
} |
| 43 |
} |
| 44 |
|