Notice.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Message; |
| 4 | |
| 5 | use AC\Asset\Style; |
| 6 | use AC\Message; |
| 7 | use AC\Registerable; |
| 8 | use AC\View; |
| 9 | |
| 10 | class Notice extends Message implements Registerable |
| 11 | { |
| 12 | |
| 13 | public function render(): string |
| 14 | { |
| 15 | $data = [ |
| 16 | 'message' => $this->message, |
| 17 | 'type' => $this->type, |
| 18 | 'id' => $this->id, |
| 19 | ]; |
| 20 | |
| 21 | $view = new View($data); |
| 22 | $view->set_template('message/notice'); |
| 23 | |
| 24 | return $view->render(); |
| 25 | } |
| 26 | |
| 27 | public function register(): void |
| 28 | { |
| 29 | if (apply_filters('ac/suppress_site_wide_notices', false, $this->id)) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | add_action('admin_notices', [$this, 'display']); |
| 34 | add_action('network_admin_notices', [$this, 'display']); |
| 35 | add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); |
| 36 | } |
| 37 | |
| 38 | public function enqueue_scripts(): void |
| 39 | { |
| 40 | $style = new Style('ac-message'); |
| 41 | $style->enqueue(); |
| 42 | } |
| 43 | |
| 44 | } |