Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-notice
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-notice
Commits
c269953d
Commit
c269953d
authored
6 years ago
by
Grzegorz Rola
Browse files
Options
Downloads
Patches
Plain Diff
init
parent
1cebcbb7
No related branches found
No related tags found
No related merge requests found
Pipeline
#6280
passed with warnings
6 years ago
Stage: tools
Stage: tests
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.editorconfig
+3
-2
3 additions, 2 deletions
.editorconfig
src/WPDesk/Notice/AjaxHandler.php
+46
-1
46 additions, 1 deletion
src/WPDesk/Notice/AjaxHandler.php
src/WPDesk/Notice/PermanentDismissibleNotice.php
+13
-5
13 additions, 5 deletions
src/WPDesk/Notice/PermanentDismissibleNotice.php
with
62 additions
and
8 deletions
.editorconfig
+
3
−
2
View file @
c269953d
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/WPDesk/Notice/AjaxHandler.php
+
46
−
1
View file @
c269953d
...
@@ -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
();
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/WPDesk/Notice/DismissibleNotice.php
→
src/WPDesk/Notice/
Permanent
DismissibleNotice.php
+
13
−
5
View file @
c269953d
...
@@ -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
Permanent
DismissibleNotice
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 $notice
DismissOption
Name Notice dismiss option name.
* @param string $noticeName Notice dismiss option name.
*/
*/
public
function
__construct
(
$noticeType
,
$noticeContent
,
$notice
DismissOption
Name
)
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
->
notice
DismissOption
Name
));
$attributesAsString
.
=
sprintf
(
'data-
notice-name
="%1$s"'
,
esc_attr
(
$this
->
noticeName
));
return
$attributesAsString
;
return
$attributesAsString
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment