Automattic\WooCommerce\Blocks\Utils

BlockTemplateUtils::create_new_block_template_object()public staticWC 1.0

Build a new template object so that we can make Woo Blocks default templates available in the current theme should they not have any.

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

Хуков нет.

Возвращает

Объект. Block template object.

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

$result = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, $template_is_from_theme );
$template_file(строка) (обязательный)
Block template file path.
$template_type(строка) (обязательный)
wp_template or wp_template_part.
$template_slug(строка) (обязательный)
Block template slug e.g. single-product.
$template_is_from_theme(true|false)
If the block template file is being loaded from the current theme instead of Woo Blocks.
По умолчанию: false

Код BlockTemplateUtils::create_new_block_template_object() WC 8.7.0

public static function create_new_block_template_object( $template_file, $template_type, $template_slug, $template_is_from_theme = false ) {
	$theme_name = wp_get_theme()->get( 'TextDomain' );

	$new_template_item = array(
		'slug'        => $template_slug,
		'id'          => $template_is_from_theme ? $theme_name . '//' . $template_slug : self::PLUGIN_SLUG . '//' . $template_slug,
		'path'        => $template_file,
		'type'        => $template_type,
		'theme'       => $template_is_from_theme ? $theme_name : self::PLUGIN_SLUG,
		// 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.
		'source'      => $template_is_from_theme ? 'theme' : 'plugin',
		'title'       => self::get_block_template_title( $template_slug ),
		'description' => self::get_block_template_description( $template_slug ),
		'post_types'  => array(), // Don't appear in any Edit Post template selector dropdown.
	);

	return (object) $new_template_item;
}