_block_template_render_without_post_block_context()WP 5.8.0

Removes post details from block context when rendering a block template.

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

Массив. Filtered context.

Использование

_block_template_render_without_post_block_context( $context );
$context(массив) (обязательный)
Default context.

Список изменений

С версии 5.8.0 Введена.

Код _block_template_render_without_post_block_context() WP 6.5.2

function _block_template_render_without_post_block_context( $context ) {
	/*
	 * When loading a template directly and not through a page that resolves it,
	 * the top-level post ID and type context get set to that of the template.
	 * Templates are just the structure of a site, and they should not be available
	 * as post context because blocks like Post Content would recurse infinitely.
	 */
	if ( isset( $context['postType'] ) && 'wp_template' === $context['postType'] ) {
		unset( $context['postId'] );
		unset( $context['postType'] );
	}

	return $context;
}