From 9a761d33ba7aeaec0d8c850b3c8081849974dc7a Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Mon, 27 Jun 2022 10:27:05 +1000 Subject: [PATCH] Post Template: Ensure layout classnames are not attached to inner li elements (#41827) * Post Template: Ensure layout classnames are not attached to inner li elements * Fix linting issue * Clarify dynamic set to false comment. Co-authored-by: ramonjd --- .../block-library/src/post-template/index.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index 9c36778bcf8a6..6df6a8f2cc584 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -82,17 +82,29 @@ function render_block_core_post_template( $attributes, $content, $block ) { $content = ''; while ( $query->have_posts() ) { $query->the_post(); + + // Get an instance of the current Post Template block. + $block_instance = $block->parsed_block; + + // Set the block name to one that does not correspond to an existing registered block. + // This ensures that for the inner instances of the Post Template block, we do not render any block supports. + $block_instance['blockName'] = 'core/null'; + + // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling + // `render_callback` and ensure that no wrapper markup is included. $block_content = ( new WP_Block( - $block->parsed_block, + $block_instance, array( 'postType' => get_post_type(), 'postId' => get_the_ID(), ) ) )->render( array( 'dynamic' => false ) ); - $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) ); - $content .= '
  • ' . $block_content . '
  • '; + + // Wrap the render inner blocks in a `li` element with the appropriate post classes. + $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) ); + $content .= '
  • ' . $block_content . '
  • '; } wp_reset_postdata();