Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 8032d39

Browse files
authored
Remove the term-description from the template string (#8549)
1 parent 740cedf commit 8032d39

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

src/Utils/BlockTemplateUtils.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,44 +121,6 @@ public static function inject_theme_attribute_in_content( $template_content ) {
121121
return $template_content;
122122
}
123123

124-
/**
125-
* Remove block from parsed template content.
126-
*
127-
* @param string $template_content serialized wp_template content.
128-
* @param string $block_name Block to be removed.
129-
*
130-
* @return string Updated wp_template content.
131-
*/
132-
private static function remove_block_from_template( $template_content, $block_name ) {
133-
$new_content = '';
134-
$template_blocks = parse_blocks( $template_content );
135-
136-
self::recursive_remove_block( $template_blocks, $block_name );
137-
138-
foreach ( $template_blocks as &$block ) {
139-
$new_content .= serialize_block( $block );
140-
}
141-
142-
return $new_content;
143-
}
144-
145-
/**
146-
* Remove block recursively from block list.
147-
*
148-
* @param array $blocks Parsed blocks array.
149-
* @param string $block_name Block to be removed.
150-
* @return void
151-
*/
152-
private static function recursive_remove_block( &$blocks, $block_name ) {
153-
foreach ( $blocks as $index => &$block ) {
154-
if ( $block_name === $block['blockName'] ) {
155-
unset( $blocks[ $index ] );
156-
} elseif ( ! empty( $block['innerBlocks'] ) ) {
157-
self::recursive_remove_block( $block['innerBlocks'], $block_name );
158-
}
159-
}
160-
}
161-
162124
/**
163125
* Build a unified template object based a post Object.
164126
* Important: This method is an almost identical duplicate from wp-includes/block-template-utils.php as it was not intended for public use. It has been modified to build templates from plugins rather than themes.
@@ -239,7 +201,7 @@ public static function build_template_result_from_file( $template_file, $templat
239201
// Remove the term description block from the archive-product template
240202
// as the Product Catalog/Shop page doesn't have a description.
241203
if ( 'archive-product' === $template_file->slug ) {
242-
$template->content = self::remove_block_from_template( $template->content, 'core/term-description' );
204+
$template->content = str_replace( '<!-- wp:term-description /-->', '', $template->content );
243205
}
244206
// Plugin was agreed as a valid source value despite existing inline docs at the time of creating: https://github.com/WordPress/gutenberg/issues/36597#issuecomment-976232909.
245207
$template->source = $template_file->source ? $template_file->source : 'plugin';

0 commit comments

Comments
 (0)