Skip to content

Commit

Permalink
Simplify get_block_file_template() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Aug 1, 2024
1 parent 356f341 commit 1cf666a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1328,20 +1328,17 @@ function get_block_file_template( $id, $template_type = 'wp_template' ) {
}
list( $theme, $slug ) = $parts;

if ( get_stylesheet() !== $theme ) {
$block_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $slug );
/** This filter is documented in wp-includes/block-template-utils.php */
return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
}
if ( get_stylesheet() === $theme ) {
$template_file = _get_block_template_file( $template_type, $slug );
if ( null !== $template_file ) {
$block_template = _build_block_template_result_from_file( $template_file, $template_type );

$template_file = _get_block_template_file( $template_type, $slug );
if ( null === $template_file ) {
$block_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $slug );
/** This filter is documented in wp-includes/block-template-utils.php */
return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
/** This filter is documented in wp-includes/block-template-utils.php */
return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
}
}

$block_template = _build_block_template_result_from_file( $template_file, $template_type );
$block_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $slug );

/**
* Filters the block template object after it has been (potentially) fetched from the theme file.
Expand Down

0 comments on commit 1cf666a

Please sign in to comment.