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

strip whitespaces in render_block_core_cover #40859

Merged
merged 10 commits into from
Jun 27, 2022
15 changes: 9 additions & 6 deletions packages/block-library/src/cover/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ function render_block_core_cover( $attributes, $content ) {

$image = get_the_post_thumbnail( null, 'post-thumbnail', $attr );

$content = str_replace(
'</span><div',
'</span>' . $image . '<div',
$content
);

/*
* Inserts the featured image between the (1st) cover 'background' `span` and 'inner_container' `div`,
* and removes eventual withespace characters between the two (typically introduced at template level)
*/
$inner_container_start = '/<div\b[^>]+wp-block-cover__inner-container[\s|"][^>]*>/U';
if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) {
$offset = $matches[0][1];
$content = substr( $content, 0, $offset ) . $image . substr( $content, $offset );
}
} else {
if ( in_the_loop() ) {
update_post_thumbnail_cache();
Expand Down