SGINoticeAdapter.php
6 years ago
SGNotice.php
6 years ago
SGNoticeAdapterWordpress.php
6 years ago
SGNoticeHandler.php
6 years ago
SGNoticeAdapterWordpress.php
51 lines
| 1 | <?php |
| 2 | require_once(dirname(__FILE__).'/SGINoticeAdapter.php'); |
| 3 | |
| 4 | class SGNoticeAdapterWordpress implements SGINoticeAdapter |
| 5 | { |
| 6 | protected $notices = array(); |
| 7 | |
| 8 | public function __construct() |
| 9 | { |
| 10 | $this->notices = array( |
| 11 | SG_NOTICE_SUCCESS => array(), |
| 12 | SG_NOTICE_WARNING => array(), |
| 13 | SG_NOTICE_ERROR => array() |
| 14 | ); |
| 15 | } |
| 16 | |
| 17 | public function addNotice($notice, $type, $dismissible = false, $id = '') |
| 18 | { |
| 19 | $this->notices[$type][] = array( |
| 20 | 'message' => $notice, |
| 21 | 'dismissible' => $dismissible, |
| 22 | 'id' => $id |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | public function addNoticeFromTemplate($template, $type, $dismissible = false) |
| 27 | { |
| 28 | $path = SG_NOTICE_TEMPLATES_PATH.$template.'.php'; |
| 29 | |
| 30 | ob_start(); |
| 31 | @include($path); |
| 32 | $content = ob_get_clean(); |
| 33 | |
| 34 | $this->addNotice($content, $type, $dismissible, $template); |
| 35 | } |
| 36 | |
| 37 | public function renderAll() |
| 38 | { |
| 39 | foreach ($this->notices as $type => $notices) { |
| 40 | foreach ($notices as $notice) { |
| 41 | $class = 'notice notice-'.$type; |
| 42 | if ($notice['dismissible']) { |
| 43 | $class .= ' is-dismissible'; |
| 44 | } |
| 45 | echo '<div data-notice-id="'.$notice['id'].'" class="'.$class.'"><p>'.$notice['message'].'</p></div>'; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | } |
| 50 | } |
| 51 |