BlockTemplateUtilsDuplicated::gutenberg_build_template_result_from_file()public staticWC 1.0

Build a unified template object based on a theme file.

Метод класса: BlockTemplateUtilsDuplicated{}

Хуков нет.

Возвращает

\WP_Block_Template. Template.

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

$result = BlockTemplateUtilsDuplicated::gutenberg_build_template_result_from_file( $template_file, $template_type );
$template_file(массив|объект) (обязательный)
Theme file.
$template_type(строка) (обязательный)
wp_template or wp_template_part.

Код BlockTemplateUtilsDuplicated::gutenberg_build_template_result_from_file() WC 9.6.1

public static function gutenberg_build_template_result_from_file( $template_file, $template_type ) {
	$template_file = (object) $template_file;

	// If the theme has an archive-products.html template but does not have product taxonomy templates
	// then we will load in the archive-product.html template from the theme to use for product taxonomies on the frontend.
	$template_is_from_theme = 'theme' === $template_file->source;
	$theme_name             = wp_get_theme()->get( 'TextDomain' );

        // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
	$template_content  = file_get_contents( $template_file->path );
	$template          = new \WP_Block_Template();
	$template->id      = $template_is_from_theme ? $theme_name . '//' . $template_file->slug : self::PLUGIN_SLUG . '//' . $template_file->slug;
	$template->theme   = $template_is_from_theme ? $theme_name : self::PLUGIN_SLUG;
	$template->content = self::gutenberg_inject_theme_attribute_in_content( $template_content );
	// Plugin was agreed as a valid source value despite existing inline docs at the time of creating: https://github.com/WordPress/gutenberg/issues/36597#issuecomment-976232909.
	$template->source         = $template_file->source ? $template_file->source : 'plugin';
	$template->slug           = $template_file->slug;
	$template->type           = $template_type;
	$template->title          = ! empty( $template_file->title ) ? $template_file->title : self::convert_slug_to_title( $template_file->slug );
	$template->status         = 'publish';
	$template->has_theme_file = true;
	$template->origin         = $template_file->source;
	$template->is_custom      = false; // Templates loaded from the filesystem aren't custom, ones that have been edited and loaded from the DB are.
	$template->post_types     = array(); // Don't appear in any Edit Post template selector dropdown.
	$template->area           = 'uncategorized';
	return $template;
}