_get_block_template_file() – Retrieves the template file from the theme for a given slug.

You appear to be a bot. Output may be restricted

Description

Retrieves the template file from the theme for a given slug.

Usage

$array|null = _get_block_template_file( $template_type, $slug );

Parameters

$template_type
( string ) required – 'wp_template' or 'wp_template_part'.
$slug
( string ) required – Template slug.

Returns

array|null Template.

Source

File name: wordpress/wp-includes/block-template-utils.php
Lines:

1 to 34 of 34
function _get_block_template_file( $template_type, $slug ) {
  if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
    return null;
  }

  $themes = array(
    get_stylesheet() => get_stylesheet_directory(),
    get_template()   => get_template_directory(),
  );
  foreach ( $themes as $theme_slug => $theme_dir ) {
    $template_base_paths = get_block_theme_folders( $theme_slug );
    $file_path           = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html';
    if ( file_exists( $file_path ) ) {
      $new_template_item = array(
        'slug'  => $slug,
        'path'  => $file_path,
        'theme' => $theme_slug,
        'type'  => $template_type,
      );

      if ( 'wp_template_part' === $template_type ) {
        return _add_block_template_part_area_info( $new_template_item );
      }

      if ( 'wp_template' === $template_type ) {
        return _add_block_template_info( $new_template_item );
      }

      return $new_template_item;
    }
  }

  return null;
}
 

 View on GitHub View on Trac