Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Iseard
Kudos-Donations
Commits
35d46789
Commit
35d46789
authored
Oct 13, 2021
by
Michael Iseard
Browse files
Improve handling of root styles
parent
7546e5e9
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/Controller/Admin.php
View file @
35d46789
...
...
@@ -261,13 +261,14 @@ class Admin {
/**
* Register assets for enqueuing in the block editor.
* These assets are enqueued using register_block_type in the front.
*/
public
function
register_block_editor_assets
()
{
wp_register_style
(
'kudos-donations-public'
,
Assets
::
get_asset_url
(
'/public/kudos-public.css'
),
[],
[
'kudos-donations-root'
],
$this
->
version
);
...
...
app/Controller/Front.php
View file @
35d46789
...
...
@@ -100,11 +100,11 @@ class Front {
}
/**
*
Add
root styles
to header
based on theme.
*
Get the
root styles based on theme
settings
.
*
* @return string
* @return string
The root styles to be inlined.
*/
public
function
get_root_styles
():
string
{
public
static
function
get_root_styles
():
string
{
$theme_colours
=
apply_filters
(
'kudos_theme_colors'
,
Settings
::
get_setting
(
'theme_colors'
)
);
...
...
@@ -115,17 +115,16 @@ class Front {
$secondary_dark
=
Utils
::
color_luminance
(
$secondary
,
'-0.06'
);
$secondary_darker
=
Utils
::
color_luminance
(
$secondary
,
'-0.09'
);
return
"
:root {
--kudos-theme-primary:
$primary
;
--kudos-theme-primary-dark:
$primary_dark
;
--kudos-theme-primary-darker:
$primary_darker
;
--kudos-theme-secondary:
$secondary
;
--kudos-theme-secondary-dark:
$secondary_dark
;
--kudos-theme-secondary-darker:
$secondary_darker
;
}
"
;
return
trim
(
"
:root {
--kudos-theme-primary:
$primary
;
--kudos-theme-primary-dark:
$primary_dark
;
--kudos-theme-primary-darker:
$primary_darker
;
--kudos-theme-secondary:
$secondary
;
--kudos-theme-secondary-dark:
$secondary_dark
;
--kudos-theme-secondary-darker:
$secondary_darker
;
}
"
);
}
...
...
@@ -165,27 +164,18 @@ class Front {
wp_register_style
(
'kudos-donations-public'
,
Assets
::
get_asset_url
(
'/public/kudos-public.css'
),
[],
[
'kudos-donations-root'
],
$this
->
version
);
}
/**
* Register the
asset
s used
for
block
s
.
* Register the
inline root style
s used
by
block
editor and front
.
*/
public
function
enqueue_root_styles
()
{
// Output root styles.
register_block_style
(
'iseardmedia/kudos-button'
,
[
'name'
=>
'kudos-button'
,
'label'
=>
__
(
'Kudos Button'
,
'kudos-donations'
),
'is_default'
=>
true
,
'inline_style'
=>
$this
->
get_root_styles
(),
]
);
public
function
register_root_styles
()
{
wp_register_style
(
'kudos-donations-root'
,
false
);
wp_add_inline_style
(
'kudos-donations-root'
,
$this
->
get_root_styles
());
}
/**
...
...
@@ -193,7 +183,6 @@ class Front {
*/
public
function
register_kudos
()
{
$this
->
enqueue_root_styles
();
$this
->
register_button_block
();
// If setting is not enabled the shortcode assets and registration will be skipped.
...
...
@@ -213,7 +202,7 @@ class Front {
wp_enqueue_style
(
'kudos-donations-public'
);
}
);
// Register
actual
shortcode.
// Register shortcode.
add_shortcode
(
'kudos'
,
function
(
$atts
)
{
...
...
@@ -250,9 +239,9 @@ class Front {
"donate"
,
],
"supports"
=>
[
"align"
=>
tru
e
,
"customClassName"
=>
true
,
"typography"
=>
[
"align"
=>
fals
e
,
"customClassName"
=>
true
,
"typography"
=>
[
"fontSize"
=>
false
,
],
],
...
...
app/KudosDonations.php
View file @
35d46789
...
...
@@ -107,6 +107,7 @@ class KudosDonations {
add_action
(
'wp_enqueue_scripts'
,
[
$plugin_public
,
'register_scripts'
]
);
add_action
(
'wp_enqueue_scripts'
,
[
$plugin_public
,
'register_styles'
]
);
add_action
(
'enqueue_block_assets'
,
[
$plugin_public
,
'register_root_styles'
]
);
// Used by front and admin
add_action
(
'init'
,
[
$plugin_public
,
'register_kudos'
]
);
add_action
(
'wp_footer'
,
[
$plugin_public
,
'handle_query_variables'
],
1000
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment