Changeset 53157 for trunk/src/wp-includes/blocks/gallery.php
- Timestamp:
- 04/12/2022 03:10:30 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/gallery.php
r52402 r53157 34 34 35 35 /** 36 * Adds a style tag for the --wp--style--unstable-gallery-gap var. 37 * 38 * The Gallery block needs to recalculate Image block width based on 39 * the current gap setting in order to maintain the number of flex columns 40 * so a css var is added to allow this. 41 * 42 * @param array $attributes Attributes of the block being rendered. 43 * @param string $content Content of the block being rendered. 44 * @return string The content of the block being rendered. 45 */ 46 function block_core_gallery_render( $attributes, $content ) { 47 $gap = _wp_array_get( $attributes, array( 'style', 'spacing', 'blockGap' ) ); 48 // Skip if gap value contains unsupported characters. 49 // Regex for CSS value borrowed from `safecss_filter_attr`, and used here 50 // because we only want to match against the value, not the CSS attribute. 51 $gap = preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap; 52 $class = wp_unique_id( 'wp-block-gallery-' ); 53 $content = preg_replace( 54 '/' . preg_quote( 'class="', '/' ) . '/', 55 'class="' . $class . ' ', 56 $content, 57 1 58 ); 59 // --gallery-block--gutter-size is deprecated. --wp--style--gallery-gap-default should be used by themes that want to set a default 60 // gap on the gallery. 61 $gap_value = $gap ? $gap : 'var( --wp--style--gallery-gap-default, var( --gallery-block--gutter-size, var( --wp--style--block-gap, 0.5em ) ) )'; 62 $style = '.' . $class . '{ --wp--style--unstable-gallery-gap: ' . $gap_value . '; gap: ' . $gap_value . '}'; 63 // Ideally styles should be loaded in the head, but blocks may be parsed 64 // after that, so loading in the footer for now. 65 // See https://core.trac.wordpress.org/ticket/53494. 66 add_action( 67 'wp_footer', 68 function () use ( $style ) { 69 echo '<style> ' . $style . '</style>'; 70 } 71 ); 72 return $content; 73 } 74 /** 36 75 * Registers the `core/gallery` block on server. 37 * This render callback needs to be here38 * so that the gallery styles are loaded in block-based themes.39 76 */ 40 77 function register_block_core_gallery() { … … 42 79 __DIR__ . '/gallery', 43 80 array( 44 'render_callback' => function ( $attributes, $content ) { 45 return $content; 46 }, 81 'render_callback' => 'block_core_gallery_render', 47 82 ) 48 83 );
Note: See TracChangeset
for help on using the changeset viewer.