Automattic\WooCommerce\Blocks\Utils
BlockTemplateUtils::remove_duplicate_customized_templates()
Removes customized templates that shouldn't be available. That means customized templates based on the WooCommerce default template when there is a customized template based on the theme template.
Метод класса: BlockTemplateUtils{}
Хуков нет.
Возвращает
Массив
. Filtered list of templates with only relevant templates available.
Использование
$result = BlockTemplateUtils::remove_duplicate_customized_templates( $templates, $theme_slug );
- $templates(\WP_Block_Template[]|\stdClass[]) (обязательный)
- List of templates to run the filter on.
- $theme_slug(строка) (обязательный)
- Slug of the theme currently active.
Код BlockTemplateUtils::remove_duplicate_customized_templates() BlockTemplateUtils::remove duplicate customized templates WC 9.3.3
public static function remove_duplicate_customized_templates( $templates, $theme_slug ) { $filtered_templates = array_filter( $templates, function ( $template ) use ( $templates, $theme_slug ) { if ( $template->theme === $theme_slug ) { // This is a customized template based on the theme template, so it should be returned. return true; } // This is a template customized from the WooCommerce default template. // Only return it if there isn't a customized version of the theme template. $is_there_a_customized_theme_template = array_filter( $templates, function ( $theme_template ) use ( $template, $theme_slug ) { return $theme_template->slug === $template->slug && $theme_template->theme === $theme_slug; } ); if ( $is_there_a_customized_theme_template ) { return false; } return true; }, ); return $filtered_templates; }