diff --git a/composer.json b/composer.json index b8bf84395e3de21adc9b84db656b975742c3c6b0..0d2a30309fe01f4379746d82de7c68ffbe0a729b 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "wimg/php-compatibility": "^8" }, "autoload": { - "psr-4": {"WPDesk\\Notice\\": "src/WPDesk/Notice/"} + "psr-4": {"WPDesk\\Notice\\": "src/WPDesk/Notice/"}, + "files": ["src/WPDesk/functions.php"] }, "autoload-dev": { }, diff --git a/src/WPDesk/Notice/Factory.php b/src/WPDesk/Notice/Factory.php new file mode 100644 index 0000000000000000000000000000000000000000..9408ad308cd30e2e3d24dd57f7fdf4db8ba60c2d --- /dev/null +++ b/src/WPDesk/Notice/Factory.php @@ -0,0 +1,47 @@ +<?php + +namespace WPDesk\Notice; + +/** + * Class Notice. + * + * @package WPDesk\Notice + */ +class Factory +{ + + /** + * Creates Notice object. + * + * @param string $noticeType Notice type. + * @param string $noticeContent Notice content. + * @param bool $isDismissible Is dismissible. + * @param int $priority Priority. + * + * @return Notice + */ + public static function notice($noticeContent = '', $noticeType = 'info', $isDismissible = false, $priority = 10) + { + return new Notice($noticeType, $noticeContent, $isDismissible, $priority); + } + + /** + * Creates PermanentDismissibleNotice object. + * + * @param string $noticeContent + * @param string $noticeType + * @param string $noticeName + * @param int $priority + * + * @return PermanentDismissibleNotice + */ + public static function permanentDismissibleNotice( + $noticeContent = '', + $noticeType = '', + $noticeName = '', + $priority = 10 + ) { + return new PermanentDismissibleNotice($noticeType, $noticeContent, $noticeName, $priority); + } + +} diff --git a/src/WPDesk/Notice/Notice.php b/src/WPDesk/Notice/Notice.php index cb22a16da8e5ba7fe2b7679e3da756ce5c7b8f83..3e397310c59f45e338f10e31b40b872001532065 100644 --- a/src/WPDesk/Notice/Notice.php +++ b/src/WPDesk/Notice/Notice.php @@ -59,20 +59,88 @@ class Notice /** * WPDesk_Flexible_Shipping_Notice constructor. * - * @param string $noticeType Notice type. * @param string $noticeContent Notice content. + * @param string $noticeType Notice type. * @param bool $isDismissible Is dismissible. * @param int $priority Notice priority. */ - public function __construct($noticeType, $noticeContent, $isDismissible = false, $priority = 10) + public function __construct($noticeContent, $noticeType = 'info', $isDismissible = false, $priority = 10) { - $this->noticeType = $noticeType; $this->noticeContent = $noticeContent; + $this->noticeType = $noticeType; $this->isDismissible = $isDismissible; $this->priority = $priority; $this->addAction(); } + /** + * @return string + */ + public function getNoticeContent() + { + return $this->noticeContent; + } + + /** + * @param string $noticeContent + */ + public function setNoticeContent($noticeContent) + { + $this->noticeContent = $noticeContent; + } + + /** + * @return string + */ + public function getNoticeType() + { + return $this->noticeType; + } + + /** + * @param string $noticeType + */ + public function setNoticeType($noticeType) + { + $this->noticeType = $noticeType; + } + + /** + * @return bool + */ + public function isDismissible() + { + return $this->isDismissible; + } + + /** + * @param bool $isDismissible + */ + public function setIsDismissible($isDismissible) + { + $this->isDismissible = $isDismissible; + } + + /** + * @return int + */ + public function getPriority() + { + return $this->priority; + } + + /** + * @param int $priority + */ + public function setPriority($priority) + { + $this->priority = $priority; + if ($this->isActionAdded) { + $this->removeAction(); + $this->addAction(); + } + } + /** * Add notice action. */ diff --git a/src/WPDesk/Notice/PermanentDismissibleNotice.php b/src/WPDesk/Notice/PermanentDismissibleNotice.php index fb421c4272744a97deefa8392da8c0a08a659ad2..a2a3d59e64f4e39dd715858b5536d4979d6fa704 100644 --- a/src/WPDesk/Notice/PermanentDismissibleNotice.php +++ b/src/WPDesk/Notice/PermanentDismissibleNotice.php @@ -26,15 +26,15 @@ class PermanentDismissibleNotice extends Notice /** * WPDesk_Flexible_Shipping_Notice constructor. * - * @param string $noticeType Notice type. * @param string $noticeContent Notice content. + * @param string $noticeType Notice type. * @param string $noticeName Notice dismiss option name. * @param int $priority Priority */ - public function __construct($noticeType, $noticeContent, $noticeName, $priority = 10) + public function __construct($noticeContent, $noticeType, $noticeName, $priority = 10) { - parent::__construct($noticeType, $noticeContent, true, $priority); + parent::__construct($noticeContent, $noticeType, true, $priority); $this->noticeName = $noticeName; $this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName; if (self::OPTION_VALUE_DISMISSED === get_option($this->noticeDismissOptionName, '')) { diff --git a/src/WPDesk/functions.php b/src/WPDesk/functions.php new file mode 100644 index 0000000000000000000000000000000000000000..e6b9bedb52d857d9de5934110ec9b354b32bc1f1 --- /dev/null +++ b/src/WPDesk/functions.php @@ -0,0 +1,31 @@ +<?php + +/** + * Creates Notice. + * + * @param $noticeContent + * @param string $noticeType + * @param bool $isDismissible + * @param int $priority + * + * @return \WPDesk\Notice\Notice + */ +function WPDeskNotice($noticeContent, $noticeType = 'info', $isDismissible = false, $priority = 10) +{ + return \WPDesk\Notice\Factory::notice($noticeContent, $noticeType, $isDismissible, $priority); +} + +/** + * Creates Notice. + * + * @param $noticeContent + * @param string $noticeType + * @param bool $isDismissible + * @param int $priority + * + * @return \WPDesk\Notice\Notice + */ +function WPDeskPermanentDismissibleNotice($noticeContent, $noticeType = 'info', $priority = 10) +{ + return \WPDesk\Notice\Factory::permanentDismissibleNotice($noticeContent, $noticeType, $priority); +}