Automattic\WooCommerce\Blocks\Utils
BlockTemplateUtils::remove_templates_with_custom_alternative
Removes templates from the theme or WooCommerce which have the same slug as template saved in the database with the woocommerce/woocommerce theme. Before WC migrated to the Template Registration API from WordPress, templates were saved in the database with the woocommerce/woocommerce theme instead of the theme's slug.
Метод класса: BlockTemplateUtils{}
Хуков нет.
Возвращает
Массив. List of templates with duplicates removed. The customised alternative is preferred over the theme default.
Использование
$result = BlockTemplateUtils::remove_templates_with_custom_alternative( $templates );
- $templates(WP_Block_Template[]|\stdClass[]) (обязательный)
- List of templates to run the filter on.
Код BlockTemplateUtils::remove_templates_with_custom_alternative() BlockTemplateUtils::remove templates with custom alternative WC 10.3.6
public static function remove_templates_with_custom_alternative( $templates ) {
// Get the slugs of all templates that have been customised and saved in the database.
$customised_template_slugs = array_column(
array_filter(
$templates,
function ( $template ) {
// This template has been customised and saved as a post.
return 'custom' === $template->source && ( self::PLUGIN_SLUG === $template->theme || self::DEPRECATED_PLUGIN_SLUG === $template->theme );
}
),
'slug'
);
// Remove theme and WC templates that have the same slug as a customised one.
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 ! ( 'custom' !== $template->source && in_array( $template->slug, $customised_template_slugs, true ) );
}
)
);
}