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
4e524e34
Commit
4e524e34
authored
3 years ago
by
Daniele Scasciafratte
Browse files
Options
Downloads
Patches
Plain Diff
feat(js): added support for gutenberg
parent
73496eac
No related branches found
No related tags found
1 merge request
!20
Feature/gutenberg
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/js/gutenberg.js
+29
-0
29 additions, 0 deletions
assets/js/gutenberg.js
src/WPDesk/Notice/Notice.php
+25
-2
25 additions, 2 deletions
src/WPDesk/Notice/Notice.php
src/WPDesk/Notice/views/admin-head-js-gutenberg.php
+8
-0
8 additions, 0 deletions
src/WPDesk/Notice/views/admin-head-js-gutenberg.php
with
62 additions
and
2 deletions
assets/js/gutenberg.js
0 → 100644
+
29
−
0
View file @
4e524e34
jQuery
(
document
).
ready
(
function
()
{
jQuery
(
'
.wpdesk
'
).
each
(
function
(
index
)
{
var
classList
=
jQuery
(
this
).
attr
(
'
class
'
).
split
(
/
\s
+/
);
var
type
=
''
;
jQuery
.
each
(
classList
,
function
(
index
,
item
)
{
if
(
item
.
startsWith
(
'
notice-
'
))
{
type
=
type
.
replace
(
'
notice-
'
,
''
);
}
});
content
=
this
.
innerText
;
actions
=
[];
jQuery
.
each
(
jQuery
(
this
).
find
(
'
a
'
),
function
(
index
,
item
)
{
text
=
item
.
innerText
;
actions
.
push
({
url
:
item
.
href
,
label
:
text
.
charAt
(
0
).
toUpperCase
()
+
text
.
slice
(
1
),
});
});
isDismiss
=
jQuery
(
this
).
hasClass
(
'
is-dismissible
'
);
window
.
wp
.
data
.
dispatch
(
'
core/notices
'
).
createNotice
(
type
,
content
,
{
isDismissible
:
isDismiss
,
actions
:
actions
}
);
});
}
);
This diff is collapsed.
Click to expand it.
src/WPDesk/Notice/Notice.php
+
25
−
2
View file @
4e524e34
...
...
@@ -83,6 +83,18 @@ class Notice
$this
->
addAction
();
}
/**
* @return bool
*/
public
function
isBlockEditor
()
{
if
(
!
function_exists
(
'get_current_screen'
)
)
{
require_once
ABSPATH
.
'/wp-admin/includes/screen.php'
;
}
return
\get_current_screen
()
->
is_block_editor
();
}
/**
* @return string
*/
...
...
@@ -163,6 +175,7 @@ class Notice
[
$this
,
'showNotice'
],
self
::
ADMIN_FOOTER_BASE_PRIORITY
+
intval
(
$this
->
priority
)
);
add_action
(
'admin_head'
,
[
$this
,
'addGutenbergScript'
]);
$this
->
actionAdded
=
true
;
}
}
...
...
@@ -183,6 +196,16 @@ class Notice
}
}
/**
* Enqueue admin scripts.
*/
public
function
addGutenbergScript
()
{
if
(
$this
->
isBlockEditor
())
{
include_once
'views/admin-head-js-gutenberg.php'
;
}
}
/**
* Add attribute.
*
...
...
@@ -202,9 +225,9 @@ class Notice
protected
function
getNoticeClass
()
{
if
(
'updated'
===
$this
->
noticeType
)
{
$notice_class
=
'notice '
.
$this
->
noticeType
;
$notice_class
=
'
wpdesk
notice '
.
$this
->
noticeType
;
}
else
{
$notice_class
=
'notice notice-'
.
$this
->
noticeType
;
$notice_class
=
'
wpdesk
notice notice-'
.
$this
->
noticeType
;
}
if
(
$this
->
dismissible
)
{
$notice_class
.
=
' is-dismissible'
;
...
...
This diff is collapsed.
Click to expand it.
src/WPDesk/Notice/views/admin-head-js-gutenberg.php
0 → 100644
+
8
−
0
View file @
4e524e34
<?php
if
(
!
defined
(
'ABSPATH'
)
)
{
exit
;
}
// Exit if accessed directly
?>
<script
type=
"text/javascript"
>
<?php
include
dirname
(
__FILE__
)
.
'/../../../../assets/js/gutenberg.js'
;
?>
</script>
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