diff --git a/src/Notice/AjaxHandler.php b/src/Notice/AjaxHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..19bafd9be73f7ca8f4d6fe7f8b8ba45eb3c37d0c --- /dev/null +++ b/src/Notice/AjaxHandler.php @@ -0,0 +1,16 @@ +<?php + +namespace WPDesk\Notice; + +/** + * Class Notice. + * + * @package WPDesk\Notice + */ +class AjaxHandler +{ + + + +} + diff --git a/src/Notice/DismissibleNotice.php b/src/Notice/DismissibleNotice.php new file mode 100644 index 0000000000000000000000000000000000000000..d05c133606fc4f20ce613b12a8dc9a6116d10650 --- /dev/null +++ b/src/Notice/DismissibleNotice.php @@ -0,0 +1,34 @@ +<?php + +namespace WPDesk\Notice; + +/** + * Class Notice. + * + * @package WPDesk\Notice + */ +class DismissibleNotice extends Notice +{ + + /** + * @var string + */ + private $noticeDismissOptionName; + + /** + * WPDesk_Flexible_Shipping_Notice constructor. + * + * @param string $noticeType Notice type. + * @param string $noticeContent Notice content. + * @param string $noticeDismissOptionName Notice dismiss option name. + */ + public function __construct($noticeType, $noticeContent, $noticeDismissOptionName) + { + parent::__construct($noticeType, $noticeContent, true); + $this->noticeDismissOptionName = $noticeContent; + } + + protected + +} + diff --git a/src/Notice/Notice.php b/src/Notice/Notice.php new file mode 100644 index 0000000000000000000000000000000000000000..635b530773c3aa430451fdc447ebcf66844c58bc --- /dev/null +++ b/src/Notice/Notice.php @@ -0,0 +1,99 @@ +<?php + +namespace WPDesk\Notice; + +/** + * Class Notice. + * + * @package WPDesk\Notice + */ +class Notice +{ + + const NOTICE_TYPE_ERROR = 'error'; + const NOTICE_TYPE_WARNING = 'warning'; + const NOTICE_TYPE_SUCCESS = 'success'; + const NOTICE_TYPE_INFO = 'info'; + + /** + * Notice type. + * + * @var string + */ + protected $noticeType; + + /** + * Notice content. + * + * @var string + */ + protected $noticeContent; + + /** + * Is dismissible. + * + * @var bool + */ + protected $isDismissible; + + /** + * Attributes. + * + * @var string[] + */ + protected $attributes = array(); + + /** + * WPDesk_Flexible_Shipping_Notice constructor. + * + * @param string $noticeType Notice type. + * @param string $noticeContent Notice content. + * @param bool $isDismissible Is dismissible. + */ + public function __construct($noticeType, $noticeContent, $isDismissible = false) + { + $this->noticeType = $noticeType; + $this->noticeContent = $noticeContent; + $this->isDismissible = $isDismissible; + add_action('admin_notices', [$this, 'showNotice']); + } + + /** + * Get notice class. + * + * @return string + */ + protected function getNoticeClass() + { + if ('updated' === $this->noticeType) { + $notice_class = 'notice ' . $this->noticeType; + } else { + $notice_class = 'notice notice-' . $this->noticeType; + } + if ($this->isDismissible) { + $notice_class .= ' is-dismissible'; + } + return $notice_class; + } + + /** + * Get attributes as string. + * + * @return string + */ + protected function getAttributesAsString() + { + $attribute_string = sprintf('class="%1$s"', esc_attr($this->getNoticeClass())); + return $attribute_string; + } + + /** + * Show notice; + */ + public function showNotice() + { + echo sprintf('<div %1$s><p>%2$s</p></div>', $this->getAttributesAsString(), $this->noticeContent); + } + +} +