Skip to content
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

Duotone: Avoid rendering duplicate stylesheet and SVG #33233

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,14 @@ function ( $selector ) use ( $duotone_id ) {
return $content . $duotone;
}

// Register the block support.
WP_Block_Supports::get_instance()->register(
'duotone',
array(
'register_attribute' => 'gutenberg_register_duotone_support',
)
);
add_filter( 'render_block', 'gutenberg_render_duotone_support', 10, 2 );
// This can be removed when plugin support requires WordPress 5.8.0+.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically uses the wp-code if it is present. It makes future changes in the plugin impossible to do because the core version is going to be used. Could we remove the core filters instead if they are present?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll update the code.

This is a pattern I've seen before in Gutenberg core and the only reason I've used it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

P.S. I pushed a similar fix for Group Block layout support. Do you want me to update logic there as well to use remove_filter?

if ( ! function_exists( 'wp_render_duotone_support' ) ) {
// Register the block support.
WP_Block_Supports::get_instance()->register(
'duotone',
array(
'register_attribute' => 'gutenberg_register_duotone_support',
)
);
add_filter( 'render_block', 'gutenberg_render_duotone_support', 10, 2 );
}