'{content}' => $block_content, ) ); } /* * Use this function to restore the context of the template tags * from a secondary query loop back to the main query loop. * Since we use two custom loops, it's safest to always restore. */ wp_reset_postdata(); return sprintf( '', $wrapper_attributes, $content ); } /** * Determines whether a block list contains a block that uses the featured image. * * @param WP_Block_List $inner_blocks Inner block instance. * * @return bool Whether the block list contains a block that uses the featured image. */ protected function block_core_post_template_uses_featured_image( $inner_blocks ) { foreach ( $inner_blocks as $block ) { if ( 'core/post-featured-image' === $block->name ) { return true; } if ( 'core/cover' === $block->name && ! empty( $block->attributes['useFeaturedImage'] ) ) { return true; } if ( $block->inner_blocks && block_core_post_template_uses_featured_image( $block->inner_blocks ) ) { return true; } } return false; } /** * Product Template renders inner blocks manually so we need to skip default * rendering routine for its inner blocks * * @param array $settings Array of determined settings for registering a block type. * @param array $metadata Metadata provided for registering a block type. * @return array */ public function add_block_type_metadata_settings( $settings, $metadata ) { if ( ! empty( $metadata['name'] ) && 'woocommerce/product-template' === $metadata['name'] ) { $settings['skip_inner_blocks'] = true; } return $settings; } }