Skip to content

Commit

Permalink
Use _get_block_template_file function and set $area variable. (#52708)
Browse files Browse the repository at this point in the history
* Use `_get_block_template_file` function and set $area variable.

* Update packages/block-library/src/template-part/index.php

Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>

---------

Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
  • Loading branch information
spacedmonkey and felixarntz authored Jul 18, 2023
1 parent 3dfea59 commit 211713c
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/block-library/src/template-part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ function render_block_core_template_part( $attributes ) {
$template_part_id = null;
$content = null;
$area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
$stylesheet = get_stylesheet();

if (
isset( $attributes['slug'] ) &&
isset( $attributes['theme'] ) &&
$stylesheet === $attributes['theme']
get_stylesheet() === $attributes['theme']
) {
$template_part_id = $attributes['theme'] . '//' . $attributes['slug'];
$template_part_query = new WP_Query(
Expand Down Expand Up @@ -64,22 +63,17 @@ function render_block_core_template_part( $attributes ) {
*/
do_action( 'render_block_core_template_part_post', $template_part_id, $attributes, $template_part_post, $content );
} else {
$template_part_file_path = '';
// Else, if the template part was provided by the active theme,
// render the corresponding file content.
if ( 0 === validate_file( $attributes['slug'] ) ) {
$themes = array( $stylesheet );
$template = get_template();
if ( $stylesheet !== $template ) {
$themes[] = $template;
}

foreach ( $themes as $theme ) {
$theme_folders = get_block_theme_folders( $theme );
$template_part_file_path = get_theme_file_path( '/' . $theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
if ( file_exists( $template_part_file_path ) ) {
$content = (string) file_get_contents( $template_part_file_path );
$content = '' !== $content ? _inject_theme_attribute_in_block_template_content( $content ) : '';
break;
$block_template_file = _get_block_template_file( 'wp_template_part', $attributes['slug'] );
if ( $block_template_file ) {
$template_part_file_path = $block_template_file['path'];
$content = (string) file_get_contents( $template_part_file_path );
$content = '' !== $content ? _inject_theme_attribute_in_block_template_content( $content ) : '';
if ( isset( $block_template_file['area'] ) ) {
$area = $block_template_file['area'];
}
}
}
Expand Down

0 comments on commit 211713c

Please sign in to comment.