From 09739d8db0b1c5ac01035925048661265342c58a Mon Sep 17 00:00:00 2001 From: navigatrum <6989338+navigatrum@users.noreply.github.com> Date: Thu, 5 May 2022 19:50:37 +0200 Subject: [PATCH 1/9] strip whitespaces in render_block_core_cover Follows on from [#39658]( https://github.com/WordPress/gutenberg/pull/39658) Remove whitespaces from html tags generated by `render_block_core_covermarkup` before injecting the featured image --- packages/block-library/src/cover/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index 82ff93e6c0f4d1..56253fcab30c7d 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -63,7 +63,7 @@ class="wp-block-cover__image-background" $content = str_replace( '' . $image . '(\s)+<', $content ) ); } From 849197a8039709fb08e4277f1d7a602fcc44e744 Mon Sep 17 00:00:00 2001 From: navigatrum <6989338+navigatrum@users.noreply.github.com> Date: Wed, 18 May 2022 17:18:54 +0200 Subject: [PATCH 2/9] amend regex --- packages/block-library/src/cover/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index 56253fcab30c7d..ca0245748024c6 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -63,7 +63,7 @@ class="wp-block-cover__image-background" $content = str_replace( '' . $image . '(\s)+<', $content ) + preg_replace( '/<\/span>(\s+)?
Date: Thu, 26 May 2022 12:19:46 +0200 Subject: [PATCH 3/9] Cover-block: edit regex to insert the featured img For the block layout see: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/cover/edit/index.js#L327-L367 For the HTML tags capturing by class name see: https://github.com/WordPress/gutenberg/blob/51db4bf888e6b18cf9d18266108114d61070f3ad/lib/block-supports/layout.php#L232 --- packages/block-library/src/cover/index.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index ca0245748024c6..fda9caabab19b8 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -60,10 +60,13 @@ class="wp-block-cover__image-background" esc_attr( $object_position ) ); - $content = str_replace( - '' . $image . '(\s+)?
]*wp-block-cover__background[\s|"][^>]*>.*<\/span>)\s*(]*wp-block-cover__inner-container[\s|"][^>]*>)/U', + "$1$image$2", + $content, + 1 ); } From ee8fe324f20eaad2ace7a9cbdafb4f3a8567b547 Mon Sep 17 00:00:00 2001 From: navigatrum <6989338+navigatrum@users.noreply.github.com> Date: Wed, 15 Jun 2022 20:00:25 +0200 Subject: [PATCH 4/9] edit cover block regex for featured image #4 For the block layout see: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/cover/edit/index.js#L327-L367 For the HTML tags capturing by class name see: https://github.com/WordPress/gutenberg/blob/51db4bf888e6b18cf9d18266108114d61070f3ad/lib/block-supports/layout.php#L232 --- packages/block-library/src/cover/index.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index fda9caabab19b8..40dc8cdd588cd5 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -62,12 +62,11 @@ class="wp-block-cover__image-background" /* 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) */ - $content = preg_replace( - '/(]*wp-block-cover__background[\s|"][^>]*>.*<\/span>)\s*(]*wp-block-cover__inner-container[\s|"][^>]*>)/U', - "$1$image$2", - $content, - 1 - ); + $inner_container_start = /]+wp-block-cover__inner-container[\s|"][^>]*>/U; + if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) { + list( $fullmatch, $offset ) = $matches[0]; + $content = substr( $content, 0, $offset ) . $image_tag . substr( $content, $offset ); + } } From 2981dd774ff0cab8ab473dddcc0a9a9f3f19b16c Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Thu, 23 Jun 2022 17:22:22 +0200 Subject: [PATCH 5/9] Add quotes around the regexp --- packages/block-library/src/cover/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index 40dc8cdd588cd5..57000a5dfff0f8 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -62,7 +62,7 @@ class="wp-block-cover__image-background" /* 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 = /]+wp-block-cover__inner-container[\s|"][^>]*>/U; + $inner_container_start = '/]+wp-block-cover__inner-container[\s|"][^>]*>/U'; if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) { list( $fullmatch, $offset ) = $matches[0]; $content = substr( $content, 0, $offset ) . $image_tag . substr( $content, $offset ); From e374216724d613e5a5f140821bb8d6c842261d61 Mon Sep 17 00:00:00 2001 From: navigatrum <6989338+navigatrum@users.noreply.github.com> Date: Fri, 24 Jun 2022 20:39:00 +0200 Subject: [PATCH 6/9] close bracket ad reformat comment --- packages/block-library/src/cover/index.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index 57000a5dfff0f8..a9dc1ff9262db1 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -60,10 +60,12 @@ class="wp-block-cover__image-background" esc_attr( $object_position ) ); - /* 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) */ + /* + * 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 = '/]+wp-block-cover__inner-container[\s|"][^>]*>/U'; - if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) { + if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) { list( $fullmatch, $offset ) = $matches[0]; $content = substr( $content, 0, $offset ) . $image_tag . substr( $content, $offset ); } From 7d65028276cd11eb6a3ba95cce12bb15b0539652 Mon Sep 17 00:00:00 2001 From: navigatrum <6989338+navigatrum@users.noreply.github.com> Date: Sat, 25 Jun 2022 03:45:24 +0200 Subject: [PATCH 7/9] retry to fix --- packages/block-library/src/cover/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index a9dc1ff9262db1..d234c0c82b661f 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -66,8 +66,8 @@ class="wp-block-cover__image-background" */ $inner_container_start = '/]+wp-block-cover__inner-container[\s|"][^>]*>/U'; if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) { - list( $fullmatch, $offset ) = $matches[0]; - $content = substr( $content, 0, $offset ) . $image_tag . substr( $content, $offset ); + $offset = $matches[0][1]; + $content = substr( $content, 0, $offset ) . $image . substr( $content, $offset ); } } From 98424c753fbec2bc51f6d560fd731d586c84ea1d Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Mon, 27 Jun 2022 13:01:01 +0200 Subject: [PATCH 8/9] Update packages/block-library/src/cover/index.php --- packages/block-library/src/cover/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index d234c0c82b661f..aae656376384c3 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -69,7 +69,6 @@ class="wp-block-cover__image-background" $offset = $matches[0][1]; $content = substr( $content, 0, $offset ) . $image . substr( $content, $offset ); } - } return $content; From 7cd71a269ab219b605436650d1e4a274da0b99c5 Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Mon, 27 Jun 2022 13:01:07 +0200 Subject: [PATCH 9/9] Update packages/block-library/src/cover/index.php --- packages/block-library/src/cover/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/cover/index.php b/packages/block-library/src/cover/index.php index aae656376384c3..e2c23b9c99421d 100644 --- a/packages/block-library/src/cover/index.php +++ b/packages/block-library/src/cover/index.php @@ -66,7 +66,7 @@ class="wp-block-cover__image-background" */ $inner_container_start = '/]+wp-block-cover__inner-container[\s|"][^>]*>/U'; if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) { - $offset = $matches[0][1]; + $offset = $matches[0][1]; $content = substr( $content, 0, $offset ) . $image . substr( $content, $offset ); } }