WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Automattic\WooCommerce\Blocks

BlockTemplatesController::remove_theme_templates_with_custom_alternative() public WC 1.0

Removes templates that were added to a theme's block-templates directory, but already had a customised version saved in the database.

{} Это метод класса: BlockTemplatesController{}

Хуков нет.

Возвращает

Массив. List of templates with duplicates removed. The customised alternative is preferred over the theme default.

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

$BlockTemplatesController = new BlockTemplatesController();
$BlockTemplatesController->remove_theme_templates_with_custom_alternative( $templates );
$templates(\WP_Block_Template[]|\stdClass[]) (обязательный)
List of templates to run the filter on.

Код BlockTemplatesController::remove_theme_templates_with_custom_alternative() WC 6.1.0

public function remove_theme_templates_with_custom_alternative( $templates ) {

	// Get the slugs of all templates that have been customised and saved in the database.
	$customised_template_slugs = array_map(
		function( $template ) {
			return $template->slug;
		},
		array_values(
			array_filter(
				$templates,
				function( $template ) {
					// This template has been customised and saved as a post.
					return 'custom' === $template->source;
				}
			)
		)
	);

	// Remove theme (i.e. filesystem) templates that have the same slug as a customised one. We don't need to check
	// for `woocommerce` in $template->source here because woocommerce templates won't have been added to $templates
	// if a saved version was found in the db. This only affects saved templates that were saved BEFORE a theme
	// template with the same slug was added.
	return array_values(
		array_filter(
			$templates,
			function( $template ) use ( $customised_template_slugs ) {
				// This template has been customised and saved as a post, so return it.
				return ! ( 'theme' === $template->source && in_array( $template->slug, $customised_template_slugs, true ) );
			}
		)
	);
}