Skip to content

Commit

Permalink
Gallery Block: Use wp_enqueue_block_support_styles() if possible (#43779
Browse files Browse the repository at this point in the history
)

In the Gallery Block, use `wp_enqueue_block_support_styles()` if it's available, and if it supports the `$priority` arg.
  • Loading branch information
ockham authored Sep 5, 2022
1 parent d8bd044 commit 0a51142
Showing 1 changed file with 11 additions and 1 deletion.
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() )
) {
wp_enqueue_block_support_styles( $style, 11 );
} else {
gutenberg_enqueue_block_support_styles( $style, 11 );
}
return $content;
}
/**
Expand Down

0 comments on commit 0a51142

Please sign in to comment.