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

Commit

Permalink
Remove the term-description from the template string (#8549)
Browse files Browse the repository at this point in the history
  • Loading branch information
albarin authored Feb 27, 2023
1 parent 740cedf commit 8032d39
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions src/Utils/BlockTemplateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,44 +121,6 @@ public static function inject_theme_attribute_in_content( $template_content ) {
return $template_content;
}

/**
* Remove block from parsed template content.
*
* @param string $template_content serialized wp_template content.
* @param string $block_name Block to be removed.
*
* @return string Updated wp_template content.
*/
private static function remove_block_from_template( $template_content, $block_name ) {
$new_content = '';
$template_blocks = parse_blocks( $template_content );

self::recursive_remove_block( $template_blocks, $block_name );

foreach ( $template_blocks as &$block ) {
$new_content .= serialize_block( $block );
}

return $new_content;
}

/**
* Remove block recursively from block list.
*
* @param array $blocks Parsed blocks array.
* @param string $block_name Block to be removed.
* @return void
*/
private static function recursive_remove_block( &$blocks, $block_name ) {
foreach ( $blocks as $index => &$block ) {
if ( $block_name === $block['blockName'] ) {
unset( $blocks[ $index ] );
} elseif ( ! empty( $block['innerBlocks'] ) ) {
self::recursive_remove_block( $block['innerBlocks'], $block_name );
}
}
}

/**
* Build a unified template object based a post Object.
* 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.
Expand Down Expand Up @@ -239,7 +201,7 @@ public static function build_template_result_from_file( $template_file, $templat
// Remove the term description block from the archive-product template
// as the Product Catalog/Shop page doesn't have a description.
if ( 'archive-product' === $template_file->slug ) {
$template->content = self::remove_block_from_template( $template->content, 'core/term-description' );
$template->content = str_replace( '<!-- wp:term-description /-->', '', $template->content );
}
// 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.
$template->source = $template_file->source ? $template_file->source : 'plugin';
Expand Down

0 comments on commit 8032d39

Please sign in to comment.