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

init

parent 1cebcbb7
Branches
Tags
No related merge requests found
Pipeline #6280 passed with warnings
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
root = true root = true
[*] [*]
indent_style = space
indent_size = 4
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
indent_style = tab
[*.yml] [*.yml]
indent_style = space indent_style = space
......
...@@ -15,12 +15,57 @@ class AjaxHandler implements HookablePluginDependant ...@@ -15,12 +15,57 @@ class AjaxHandler implements HookablePluginDependant
use PluginAccess; use PluginAccess;
const SCRIPTS_VERSION = '1';
const POST_FIELD_NOTICE_NAME = 'notice-name';
/**
* @var string
*/
private $assetsURL;
/**
* AjaxHandler constructor.
*
* @param string $assetsURL Assets URL.
*/
public function __construct($assetsURL)
{
$this->assetsURL = $assetsURL;
}
/** /**
* Hooks. * Hooks.
*/ */
public function hooks() public function hooks()
{ {
add_action(); add_action('admin_enqueue_scripts', [$this, 'enqueueAdminScripts']);
add_action('wp_ajax_wpdesk_notice_dismiss', [$this, 'processAjaxNoticeDismiss']);
}
/**
* Enqueue admin scripts.
*/
public function enqueueAdminScripts()
{
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_register_script(
'wpdesk_notice',
trailingslashit($this->assetsURL) . 'js/' . $suffix . '.js',
array( 'jquery' ),
self::SCRIPTS_VERSION
);
}
/**
* Process AJAX notice dismiss.
*/
public function processAjaxNoticeDismiss()
{
if (isset($_POST[self::POST_FIELD_NOTICE_NAME])) {
$noticeName = $_POST[self::POST_FIELD_NOTICE_NAME];
delete_option(PermanentDismissibleNotice::OPTION_NAME_PREFIX . $noticeName);
}
die();
} }
} }
......
...@@ -7,9 +7,16 @@ namespace WPDesk\Notice; ...@@ -7,9 +7,16 @@ namespace WPDesk\Notice;
* *
* @package WPDesk\Notice * @package WPDesk\Notice
*/ */
class DismissibleNotice extends Notice class PermanentDismissibleNotice extends Notice
{ {
const OPTION_NAME_PREFIX = 'wpdesk_notice_dismiss_';
/**
* @var string
*/
private $noticeName;
/** /**
* @var string * @var string
*/ */
...@@ -20,12 +27,13 @@ class DismissibleNotice extends Notice ...@@ -20,12 +27,13 @@ class DismissibleNotice extends Notice
* *
* @param string $noticeType Notice type. * @param string $noticeType Notice type.
* @param string $noticeContent Notice content. * @param string $noticeContent Notice content.
* @param string $noticeDismissOptionName Notice dismiss option name. * @param string $noticeName Notice dismiss option name.
*/ */
public function __construct($noticeType, $noticeContent, $noticeDismissOptionName) public function __construct($noticeType, $noticeContent, $noticeName)
{ {
parent::__construct($noticeType, $noticeContent, true); parent::__construct($noticeType, $noticeContent, true);
$this->noticeDismissOptionName = $noticeContent; $this->noticeName = $noticeName;
$this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName;
} }
/** /**
...@@ -36,7 +44,7 @@ class DismissibleNotice extends Notice ...@@ -36,7 +44,7 @@ class DismissibleNotice extends Notice
protected function getAttributesAsString() protected function getAttributesAsString()
{ {
$attributesAsString = parent::getAttributesAsString(); $attributesAsString = parent::getAttributesAsString();
$attributesAsString .= sprintf('data-dismiss-option="%1$s"', esc_attr($this->noticeDismissOptionName)); $attributesAsString .= sprintf('data-notice-name="%1$s"', esc_attr($this->noticeName));
return $attributesAsString; return $attributesAsString;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment