-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport defaultDuotone option #12
Changes from 3 commits
40418ea
f2f1a7d
41080f4
18bcda6
e6ae1e1
203c064
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -574,6 +574,10 @@ | |
add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); | ||
add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); | ||
|
||
// SVG filters like duotone have to be loaded at the beginning of the body in both admin and the front-end. | ||
add_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); | ||
add_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ajlende This will load SVG filters on every admin page. We only need them on editor pages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in 41080f4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find a better place for it than At least with |
||
|
||
add_action( 'wp_default_styles', 'wp_default_styles' ); | ||
add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2336,6 +2336,35 @@ function wp_enqueue_global_styles() { | |
wp_enqueue_style( 'global-styles' ); | ||
} | ||
|
||
/** | ||
* Render the SVG filters supplied by theme.json. | ||
* | ||
* Note that this doesn't render the per-block user-defined | ||
* filters which are handled by wp_render_duotone_support, | ||
* but it should be rendered before the filtered content | ||
* in the body to satisfy Safari's rendering quirks. | ||
* | ||
* @since 5.9.0 | ||
*/ | ||
function wp_global_styles_render_svg_filters() { | ||
/* | ||
* When calling via the in_admin_header action, we only want to render the | ||
* SVGs on the post editor page. | ||
*/ | ||
global $pagenow; | ||
if ( | ||
is_admin() && | ||
( 'post.php' !== $pagenow || 'edit' !== $_GET['action'] ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The site editor doesn't need the SVGs because it's rendering the editor in an iframe that doesn't have access to the filters rendered in the page. WordPress/gutenberg#37727 is open to render the SVGs via JavaScript into that iframe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even so, I think There are a bunch of other checks that are happening with that method, so it's probably safer to use. |
||
) { | ||
return; | ||
} | ||
|
||
$filters = wp_get_global_styles_svg_filters(); | ||
if ( ! empty( $filters ) ) { | ||
echo $filters; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the editor scripts and styles for all registered block types | ||
* should be enqueued on the current screen. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use old logic from
should_override_preset
instead of introducing a new method and removing the old one?This method won't be private after WordPress#2322.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible. I would strongly advise against using the old one.
The old method is confusing because it returns either the boolean or the inverse of the boolean when a path is passed. Making the return consistent—the boolean or the boolean at the end of a path—is much easier to understand. And it doesn't require checking if the path argument is an array at both the call site and the method.