From 8639a8bafd89d0e6f74659c843aa5729e334d601 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 20 Aug 2026 17:06:24 +0200 Subject: [PATCH 1/3] Export: Remove image classes by token --- includes/create-theme/theme-templates.php | 13 ++++++++++--- tests/test-theme-templates.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/includes/create-theme/theme-templates.php b/includes/create-theme/theme-templates.php index 04fd1ffa..726737b7 100644 --- a/includes/create-theme/theme-templates.php +++ b/includes/create-theme/theme-templates.php @@ -336,14 +336,21 @@ private static function eliminate_environment_specific_content_from_block( $bloc if ( in_array( $block['blockName'], array( 'core/image', 'core/cover' ), true ) ) { // remove id attribute from image and cover blocks if ( isset( $block['attrs']['id'] ) ) { - $image_id = $block['attrs']['id']; + $image_class = 'wp-image-' . $block['attrs']['id']; unset( $block['attrs']['id'] ); - // remove wp-image-[id] class from inner content + // Remove the matching class token without changing similar text elsewhere. foreach ( $block['innerContent'] as $inner_key => $inner_content ) { if ( is_null( $inner_content ) ) { continue; } - $block['innerContent'][ $inner_key ] = str_replace( 'wp-image-' . $image_id, '', $inner_content ); + + $processor = new WP_HTML_Tag_Processor( $inner_content ); + while ( $processor->next_tag() ) { + if ( $processor->has_class( $image_class ) ) { + $processor->remove_class( $image_class ); + } + } + $block['innerContent'][ $inner_key ] = $processor->__toString(); } } } diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index 8bd64c45..b42fea3c 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -119,6 +119,20 @@ public function test_eliminate_id_from_image() { $this->assertStringNotContainsString( 'wp-image-635', $new_template->content ); } + public function test_eliminate_image_id_only_removes_matching_class_token() { + $template = new stdClass(); + $template->content = ' + +
+ + '; + $new_template = CBT_Theme_Templates::eliminate_environment_specific_content( $template ); + + $this->assertStringContainsString( 'class="custom-wp-image-635"', $new_template->content ); + $this->assertStringContainsString( '', $new_template->content ); + $this->assertStringNotContainsString( ' wp-image-635"', $new_template->content ); + } + public function test_eliminate_taxQuery_from_query_loop() { $template = new stdClass(); $template->content = ' From 732521a5994c1c3bc1f37b700fb5aebdf3fce8fe Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 20 Aug 2026 17:44:14 +0200 Subject: [PATCH 2/3] Refine image class cleanup --- includes/create-theme/theme-templates.php | 4 ++-- tests/test-theme-templates.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/create-theme/theme-templates.php b/includes/create-theme/theme-templates.php index 726737b7..0c2a63ec 100644 --- a/includes/create-theme/theme-templates.php +++ b/includes/create-theme/theme-templates.php @@ -340,12 +340,12 @@ private static function eliminate_environment_specific_content_from_block( $bloc unset( $block['attrs']['id'] ); // Remove the matching class token without changing similar text elsewhere. foreach ( $block['innerContent'] as $inner_key => $inner_content ) { - if ( is_null( $inner_content ) ) { + if ( is_null( $inner_content ) || false === strpos( $inner_content, $image_class ) ) { continue; } $processor = new WP_HTML_Tag_Processor( $inner_content ); - while ( $processor->next_tag() ) { + while ( $processor->next_tag( 'img' ) ) { if ( $processor->has_class( $image_class ) ) { $processor->remove_class( $image_class ); } diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index b42fea3c..d63b75f2 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -123,13 +123,13 @@ public function test_eliminate_image_id_only_removes_matching_class_token() { $template = new stdClass(); $template->content = ' -
+
wp-image-635?template data
'; $new_template = CBT_Theme_Templates::eliminate_environment_specific_content( $template ); $this->assertStringContainsString( 'class="custom-wp-image-635"', $new_template->content ); - $this->assertStringContainsString( '', $new_template->content ); + $this->assertStringContainsString( '
wp-image-635?template data
', $new_template->content ); $this->assertStringNotContainsString( ' wp-image-635"', $new_template->content ); } From 26ad6b083c53d05701fb931a941551c2c7f441d6 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Tue, 29 Sep 2026 10:18:28 +0200 Subject: [PATCH 3/3] Remove image class from cover background divs Covers with fixed or repeated backgrounds render the wp-image-{id} class on a div rather than an img, so scan every tag instead of filtering by tag name. Co-Authored-By: Claude Opus 5.5 --- includes/create-theme/theme-templates.php | 3 ++- tests/test-theme-templates.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/create-theme/theme-templates.php b/includes/create-theme/theme-templates.php index 0c2a63ec..88f30572 100644 --- a/includes/create-theme/theme-templates.php +++ b/includes/create-theme/theme-templates.php @@ -344,8 +344,9 @@ private static function eliminate_environment_specific_content_from_block( $bloc continue; } + // Covers with fixed or repeated backgrounds put the class on a div, not an img. $processor = new WP_HTML_Tag_Processor( $inner_content ); - while ( $processor->next_tag( 'img' ) ) { + while ( $processor->next_tag() ) { if ( $processor->has_class( $image_class ) ) { $processor->remove_class( $image_class ); } diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index d63b75f2..0a81da24 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -133,6 +133,20 @@ public function test_eliminate_image_id_only_removes_matching_class_token() { $this->assertStringNotContainsString( ' wp-image-635"', $new_template->content ); } + public function test_eliminate_image_id_from_cover_with_fixed_background() { + $template = new stdClass(); + $template->content = ' + +
+ + '; + $new_template = CBT_Theme_Templates::eliminate_environment_specific_content( $template ); + + $this->assertStringNotContainsString( '"id":635', $new_template->content ); + $this->assertStringNotContainsString( 'wp-image-635', $new_template->content ); + $this->assertStringContainsString( 'class="wp-block-cover__image-background has-parallax"', $new_template->content ); + } + public function test_eliminate_taxQuery_from_query_loop() { $template = new stdClass(); $template->content = '