# get_block_file_template()

URL: https://chugunov.pro/api-wordpress/functions/get_block_file_template/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.9.0.

## Сигнатура

```php
get_block_file_template( string $id, string $template_type = 'wp_template' ): WP_Block_Template|null
```

## Описание

Это резервный вариант для get_block_template(), используемый, когда в базе данных не найдено ни одного шаблона.
Также проверяет шаблоны, зарегистрированные через Template Registration API.

## Параметры

- `$id` `string` — обязательный. Уникальный идентификатор шаблона (пример: 'theme_slug//template_slug').
- `$template_type` `string` — необязательный, по умолчанию `'wp_template'`. Тип шаблона. Либо 'wp_template', либо 'wp_template_part'.
  
  Значение по умолчанию — 'wp_template'.

## Возвращаемое значение

`WP_Block_Template|null`

## Исходный код

Файл: `wp-includes/block-template-utils.php:1363`

```php
function get_block_file_template( $id, $template_type = 'wp_template' ) {
	/**
	 * Filters the block template object before the theme file discovery takes place.
	 *
	 * Return a non-null value to bypass the WordPress theme file discovery.
	 *
	 * @since 5.9.0
	 *
	 * @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
	 *                                               or null to allow WP to run its normal queries.
	 * @param string                 $id             Template unique identifier (example: 'theme_slug//template_slug').
	 * @param string                 $template_type  Template type. Either 'wp_template' or 'wp_template_part'.
	 */
	$block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
	if ( ! is_null( $block_template ) ) {
		return $block_template;
	}

	$parts = explode( '//', $id, 2 );
	if ( count( $parts ) < 2 ) {
		/** This filter is documented in wp-includes/block-template-utils.php */
		return apply_filters( 'get_block_file_template', null, $id, $template_type );
	}
	list( $theme, $slug ) = $parts;

	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 );

			/** 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 = WP_Block_Templates_Registry::get_instance()->get_by_slug( $slug );

	if ( $block_template ) {
		$block_template->content = apply_block_hooks_to_content(
			$block_template->content,
			$block_template,
			'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata'
		);
	}

	/**
	 * Filters the block template object after it has been (potentially) fetched from the theme file.
	 *
	 * @since 5.9.0
	 *
	 * @param WP_Block_Template|null $block_template The found block template, or null if there is none.
	 * @param string                 $id             Template unique identifier (example: 'theme_slug//template_slug').
	 * @param string                 $template_type  Template type. Either 'wp_template' or 'wp_template_part'.
	 */
	return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
}
```

## История изменений

- 5.9.0 — Introduced.

## Связанные

Использует: `WP_Block_Templates_Registry::get_instance`, [`apply_block_hooks_to_content`](https://chugunov.pro/api-wordpress/functions/apply_block_hooks_to_content/), [`_build_block_template_result_from_file`](https://chugunov.pro/api-wordpress/functions/_build_block_template_result_from_file/), [`_get_block_template_file`](https://chugunov.pro/api-wordpress/functions/_get_block_template_file/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_REST_Templates_Controller::get_item`, [`get_block_template`](https://chugunov.pro/api-wordpress/functions/get_block_template/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_block_file_template/
