Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ function _remove_theme_attribute_from_template_part_block( &$block ) {
*/
function _build_block_template_result_from_file( $template_file, $template_type ) {
$default_template_types = get_default_block_template_types();
$template_content = file_get_contents( $template_file['path'] );
$theme = get_stylesheet();

$template = new WP_Block_Template();
Expand All @@ -532,6 +531,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
$template->has_theme_file = true;
$template->is_custom = true;
$template->modified = null;
$template->content = file_get_contents( $template_file['path'] );
Copy link
Contributor

@ockham ockham Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final suggestion: Let's set $template->content right below $template->theme (i.e. on R526 if I'm not mistaken).

That's the position where it originally was before we started porting Block Hooks code to Core, and it's also more consistent with _build_block_template_result_from_post:

$template->theme = $theme;
$template->content = $post->post_content;
$template->slug = $post->post_name;


if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) {
$template->description = $default_template_types[ $template_file['slug'] ]['description'];
Expand All @@ -554,7 +554,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $template );
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $template );
}
$blocks = parse_blocks( $template_content );
$blocks = parse_blocks( $template->content );
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );

return $template;
Expand Down