-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Gallery Block: Use wp_enqueue_block_support_styles()
if possible
#43779
Gallery Block: Use wp_enqueue_block_support_styles()
if possible
#43779
Conversation
if ( | ||
function_exists( 'wp_enqueue_block_support_styles' ) && | ||
2 === count( ( new ReflectionFunction( 'wp_enqueue_block_support_styles' ) )->getParameters() ) | ||
) { |
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.
An alternative would be
if ( | |
function_exists( 'wp_enqueue_block_support_styles' ) && | |
2 === count( ( new ReflectionFunction( 'wp_enqueue_block_support_styles' ) )->getParameters() ) | |
) { | |
if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) { |
but I find that less semantic. It also is less accurate, e.g. during the 6.1 alpha phase (now): It would evaluate to false
even once WordPress/wordpress-develop#3158 is merged (and used in a local install).
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.
I've tested this classic and block themes. Editor and frontend match and the CSS is loading as expected. Thank you! 👍
It seems like a clever approach.
I was just curious to know why we couldn't leave gutenberg_enqueue_block_support_styles
working as it is and remove it later once migration has occurred, or the minimum version is 6.1?
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.
I was just curious to know why we couldn't leave gutenberg_enqueue_block_support_styles working as it is and remove it later once migration has occurred, or the minimum version is 6.1?
I don't have an answer but would also like to understand this. FYI, It was mentioned by @gziolo in #43440 (comment) that we should:
refactor ocurrences of
gutenberg_enqueue_block_support_styles in core blocks in the Gutenberg plugin
Thanks, folks!
Aside from what Michal mentioned, I think the reason is that we don't want to have any |
It isn't the most elegant solution to run this type of check that exists only because of the limitation of the Gutenberg plugin. You can also use Webpack to rewrite PHP files during the build to use the function that patches older versions of WordPress, similar to what we have here: gutenberg/tools/webpack/blocks.js Lines 25 to 30 in 0a51142
|
Thanks @gziolo -- and TIL! That sounds like a good fit. I'll revert and will file an alternative PR. We might need to tweak the Webpack logic a bit though to replace the |
It's nice to have, but I wouldn't make it too easy so it becomes too tempting to use everywhere. |
What?
In the Gallery Block, use
wp_enqueue_block_support_styles()
if it's available, and if it supports the$priority
arg.Why?
To enable us to use the two-argument version of
wp_enqueue_block_support_styles()
(currently being backported to Core here), and eventually remove thegutenberg_enqueue_block_support_styles()
shim.How?
By checking if the function exists, and if it supports two arguments.
Testing Instructions
Verify that the Gallery block still works.