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
1
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-notice
Commits
55405eb4
Commit
55405eb4
authored
6 years ago
by
Dyszczo
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/attributes' into 'master'
Feature/attributes See merge request
!6
parents
55ce2af9
e17e185a
No related branches found
Branches containing commit
Tags
2.0.1
Tags containing commit
1 merge request
!6
Feature/attributes
Pipeline
#7927
failed with stages
in 2 hours and 51 minutes
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/WPDesk/Notice/Notice.php
+34
-4
34 additions, 4 deletions
src/WPDesk/Notice/Notice.php
src/WPDesk/Notice/PermanentDismissibleNotice.php
+3
-3
3 additions, 3 deletions
src/WPDesk/Notice/PermanentDismissibleNotice.php
with
37 additions
and
7 deletions
src/WPDesk/Notice/Notice.php
+
34
−
4
View file @
55405eb4
...
@@ -64,13 +64,20 @@ class Notice
...
@@ -64,13 +64,20 @@ class Notice
* @param string $noticeType Notice type.
* @param string $noticeType Notice type.
* @param bool $dismissible Is dismissible.
* @param bool $dismissible Is dismissible.
* @param int $priority Notice priority.
* @param int $priority Notice priority.
*/
* @param array $attributes Attributes.
public
function
__construct
(
$noticeContent
,
$noticeType
=
'info'
,
$dismissible
=
false
,
$priority
=
10
)
*/
{
public
function
__construct
(
$noticeContent
,
$noticeType
=
'info'
,
$dismissible
=
false
,
$priority
=
10
,
$attributes
=
array
()
)
{
$this
->
noticeContent
=
$noticeContent
;
$this
->
noticeContent
=
$noticeContent
;
$this
->
noticeType
=
$noticeType
;
$this
->
noticeType
=
$noticeType
;
$this
->
dismissible
=
$dismissible
;
$this
->
dismissible
=
$dismissible
;
$this
->
priority
=
$priority
;
$this
->
priority
=
$priority
;
$this
->
attributes
=
$attributes
;
$this
->
addAction
();
$this
->
addAction
();
}
}
...
@@ -176,6 +183,9 @@ class Notice
...
@@ -176,6 +183,9 @@ class Notice
if
(
$this
->
dismissible
)
{
if
(
$this
->
dismissible
)
{
$notice_class
.
=
' is-dismissible'
;
$notice_class
.
=
' is-dismissible'
;
}
}
if
(
isset
(
$this
->
attributes
[
'class'
]))
{
$notice_class
.
=
' '
.
$this
->
attributes
[
'class'
];
}
return
$notice_class
;
return
$notice_class
;
}
}
...
@@ -187,15 +197,35 @@ class Notice
...
@@ -187,15 +197,35 @@ class Notice
protected
function
getAttributesAsString
()
protected
function
getAttributesAsString
()
{
{
$attribute_string
=
sprintf
(
'class="%1$s"'
,
esc_attr
(
$this
->
getNoticeClass
()));
$attribute_string
=
sprintf
(
'class="%1$s"'
,
esc_attr
(
$this
->
getNoticeClass
()));
foreach
(
$this
->
attributes
as
$attribute_name
=>
$attribute_value
)
{
if
(
'class'
!==
$attribute_name
)
{
$attribute_string
.
=
sprintf
(
' %1$s="%2$s"'
,
esc_html
(
$attribute_name
),
esc_attr
(
$attribute_value
));
}
}
return
$attribute_string
;
return
$attribute_string
;
}
}
private
function
addParagraphToContent
()
{
if
(
0
===
strpos
(
$this
->
noticeContent
,
'<p>'
))
{
return
false
;
}
if
(
0
===
strpos
(
$this
->
noticeContent
,
'<div>'
)
||
0
===
strpos
(
$this
->
noticeContent
,
'<div '
))
{
return
false
;
}
return
true
;
}
/**
/**
* Show notice;
* Show notice;
*/
*/
public
function
showNotice
()
public
function
showNotice
()
{
{
echo
sprintf
(
'<div %1$s><p>%2$s</p></div>'
,
$this
->
getAttributesAsString
(),
$this
->
noticeContent
);
$noticeFormat
=
'<div %1$s>%2$s</div>'
;
if
(
$this
->
addParagraphToContent
())
{
$noticeFormat
=
'<div %1$s><p>%2$s</p></div>'
;
}
echo
sprintf
(
$noticeFormat
,
$this
->
getAttributesAsString
(),
$this
->
noticeContent
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/WPDesk/Notice/PermanentDismissibleNotice.php
+
3
−
3
View file @
55405eb4
...
@@ -31,11 +31,11 @@ class PermanentDismissibleNotice extends Notice
...
@@ -31,11 +31,11 @@ class PermanentDismissibleNotice extends Notice
* @param string $noticeType Notice type.
* @param string $noticeType Notice type.
* @param string $noticeName Notice dismiss option name.
* @param string $noticeName Notice dismiss option name.
* @param int $priority Priority
* @param int $priority Priority
* @param array $attributes Attributes.
*/
*/
public
function
__construct
(
$noticeContent
,
$noticeType
,
$noticeName
,
$priority
=
10
,
$attributes
=
array
())
public
function
__construct
(
$noticeContent
,
$noticeType
,
$noticeName
,
$priority
=
10
)
{
{
parent
::
__construct
(
$noticeContent
,
$noticeType
,
true
,
$priority
);
parent
::
__construct
(
$noticeContent
,
$noticeType
,
true
,
$priority
,
$attributes
);
$this
->
noticeName
=
$noticeName
;
$this
->
noticeName
=
$noticeName
;
$this
->
noticeDismissOptionName
=
static
::
OPTION_NAME_PREFIX
.
$noticeName
;
$this
->
noticeDismissOptionName
=
static
::
OPTION_NAME_PREFIX
.
$noticeName
;
if
(
self
::
OPTION_VALUE_DISMISSED
===
get_option
(
$this
->
noticeDismissOptionName
,
''
))
{
if
(
self
::
OPTION_VALUE_DISMISSED
===
get_option
(
$this
->
noticeDismissOptionName
,
''
))
{
...
...
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