Skip to content
Closed
Prev Previous commit
Next Next commit
Only call _inject_theme_attribute_in_template_part_block() if a REST …
…API request.
  • Loading branch information
felixarntz authored and ockham committed Oct 12, 2023
commit 5932fba0299d1ebf2fd7fecbbb44615805573cf1
9 changes: 6 additions & 3 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,18 @@ function _build_block_template_result_from_file( $template_file, $template_type
$template->area = $template_file['area'];
}

$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
$before_block_visitor = ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ? '_inject_theme_attribute_in_template_part_block' : null;
$after_block_visitor = null;
$hooked_blocks = get_hooked_blocks();
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
$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 );
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
if ( ! is_null( $before_block_visitor ) || ! is_null( $after_block_visitor ) ) {
$blocks = parse_blocks( $template_content );
$template_content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
}
$template->content = $template_content;

return $template;
}
Expand Down