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

Gallery Block: Use wp_enqueue_block_support_styles() if possible #43779

Merged
Merged
Changes from all commits
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
12 changes: 11 additions & 1 deletion packages/block-library/src/gallery/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ function block_core_gallery_render( $attributes, $content ) {
// Set the CSS variable to the column value, and the `gap` property to the combined gap value.
$style = '.wp-block-gallery.' . $class . '{ --wp--style--unstable-gallery-gap: ' . $gap_column . '; gap: ' . $gap_value . '}';

gutenberg_enqueue_block_support_styles( $style, 11 );
// If we're on WordPress >= 6.1, we can use `wp_enqueue_block_support_styles`, as it supports
// `$priority` as its second argument. Otherwise, we have to fall back to using our
// `gutenberg_enqueue_block_support_styles` shim.
if (
function_exists( 'wp_enqueue_block_support_styles' ) &&
2 === count( ( new ReflectionFunction( 'wp_enqueue_block_support_styles' ) )->getParameters() )
) {
Comment on lines +110 to +113
Copy link
Contributor Author

@ockham ockham Sep 1, 2022

Choose a reason for hiding this comment

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

An alternative would be

Suggested change
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).

wp_enqueue_block_support_styles( $style, 11 );
} else {
gutenberg_enqueue_block_support_styles( $style, 11 );
}
return $content;
}
/**
Expand Down