# _build_block_template_object_from_post_object()

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

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

## Сигнатура

```php
_build_block_template_object_from_post_object( WP_Post $post, array $terms = array(), array $meta = array() ): WP_Block_Template|WP_Error
```

## Описание

Это вспомогательная функция, создающая объект шаблона блока из переданного объекта записи.
Она самодостаточна: использует только информацию, переданную в аргументах, и не обращается к базе данных за дополнительными данными.

## Параметры

- `$post` `WP_Post` — обязательный. Запись шаблона.
- `$terms` `array` — необязательный, по умолчанию `array()`. Дополнительные термины для формирования объекта шаблона.
- `$meta` `array` — необязательный, по умолчанию `array()`. Дополнительные поля метаданных для формирования объекта шаблона.

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

`WP_Block_Template|WP_Error`

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

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

```php
function _build_block_template_object_from_post_object( $post, $terms = array(), $meta = array() ) {
	if ( empty( $terms['wp_theme'] ) ) {
		return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.' ) );
	}
	$theme = $terms['wp_theme'];

	$default_template_types = get_default_block_template_types();

	$template_file  = _get_block_template_file( $post->post_type, $post->post_name );
	$has_theme_file = get_stylesheet() === $theme && null !== $template_file;

	$template                 = new WP_Block_Template();
	$template->wp_id          = $post->ID;
	$template->id             = $theme . '//' . $post->post_name;
	$template->theme          = $theme;
	$template->content        = $post->post_content;
	$template->slug           = $post->post_name;
	$template->source         = 'custom';
	$template->origin         = ! empty( $meta['origin'] ) ? $meta['origin'] : null;
	$template->type           = $post->post_type;
	$template->description    = $post->post_excerpt;
	$template->title          = $post->post_title;
	$template->status         = $post->post_status;
	$template->has_theme_file = $has_theme_file;
	$template->is_custom      = empty( $meta['is_wp_suggestion'] );
	$template->author         = $post->post_author;
	$template->modified       = $post->post_modified;

	if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) {
		$template->post_types = $template_file['postTypes'];
	}

	if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) {
		$template->is_custom = false;
	}

	if ( 'wp_template_part' === $post->post_type && isset( $terms['wp_template_part_area'] ) ) {
		$template->area = $terms['wp_template_part_area'];
	}

	return $template;
}
```

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

- 6.5.3 — Introduced.

## Связанные

Использует: [`get_default_block_template_types`](https://chugunov.pro/api-wordpress/functions/get_default_block_template_types/), [`_get_block_template_file`](https://chugunov.pro/api-wordpress/functions/_get_block_template_file/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), `WP_Error::__construct`.
Используется в: [`inject_ignored_hooked_blocks_metadata_attributes`](https://chugunov.pro/api-wordpress/functions/inject_ignored_hooked_blocks_metadata_attributes/), [`_build_block_template_result_from_post`](https://chugunov.pro/api-wordpress/functions/_build_block_template_result_from_post/).

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