Skip to content
Snippets Groups Projects
Commit 1fdb7ee5 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

init

parent 0eb47262
No related branches found
No related tags found
No related merge requests found
Pipeline #6440 passed with warnings
......@@ -36,6 +36,18 @@ class Notice
*/
protected $isDismissible;
/**
* Notice hook priority.
* @var int;
*/
protected $priority;
/**
* Is action added?
* @var bool
*/
private $isActionAdded = false;
/**
* Attributes.
*
......@@ -43,6 +55,7 @@ class Notice
*/
protected $attributes = array();
/**
* WPDesk_Flexible_Shipping_Notice constructor.
*
......@@ -56,7 +69,27 @@ class Notice
$this->noticeType = $noticeType;
$this->noticeContent = $noticeContent;
$this->isDismissible = $isDismissible;
add_action('admin_notices', [$this, 'showNotice'], $priority);
$this->priority = $priority;
$this->addAction();
}
/**
* Add notice action.
*/
protected function addAction()
{
if (!$this->isActionAdded) {
add_action('admin_notices', [$this, 'showNotice'], $this->priority);
$this->isActionAdded = true;
}
}
protected function removeAction()
{
if ($this->isActionAdded) {
remove_action('admin_notices', [$this, 'showNotice'], $this->priority);
$this->isActionAdded = false;
}
}
/**
......
......@@ -38,10 +38,19 @@ class PermanentDismissibleNotice extends Notice
$this->noticeName = $noticeName;
$this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName;
if (self::OPTION_VALUE_DISMISSED === get_option($this->noticeDismissOptionName, '')) {
remove_action('admin_notices', [$this, 'showNotice'], $priority);
$this->removeAction();
}
}
/**
* Undo dismiss notice.
*/
public function undoDismiss()
{
delete_option($this->noticeDismissOptionName);
$this->addAction();
}
/**
* Get attributes as string.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment