Block Hooks API: Add TT2 theme to the list of allowed themes for Mini Cart auto-insertion (#42813)

This commit is contained in:
Tom Cafferkey 2023-12-15 08:57:26 +00:00 committed by GitHub
commit d3c497f7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Auto-inserts Mini Cart block into TT2 theme headers patterns and template parts.

View File

@ -600,7 +600,7 @@ class MiniCart extends AbstractBlock {
* *
* @since $VID:$ * @since $VID:$
*/ */
$pattern_exclude_list = apply_filters( 'woocommerce_blocks_mini_cart_auto_insert_pattern_exclude_list', [] ); $pattern_exclude_list = apply_filters( 'woocommerce_blocks_mini_cart_auto_insert_pattern_exclude_list', array( 'twentytwentytwo/header-centered-logo', 'twentytwentytwo/header-stacked' ) );
/** /**
* A list of theme slugs to execute this with. This is a temporary * A list of theme slugs to execute this with. This is a temporary
@ -609,7 +609,7 @@ class MiniCart extends AbstractBlock {
* *
* @since $VID:$ * @since $VID:$
*/ */
$theme_include_list = apply_filters( 'woocommerce_blocks_mini_cart_auto_insert_theme_include_list', array( 'Twenty Twenty-Four', 'Twenty Twenty-Three' ) ); $theme_include_list = apply_filters( 'woocommerce_blocks_mini_cart_auto_insert_theme_include_list', array( 'Twenty Twenty-Four', 'Twenty Twenty-Three', 'Twenty Twenty-Two' ) );
if ( $context && in_array( $active_theme_name, $theme_include_list, true ) ) { if ( $context && in_array( $active_theme_name, $theme_include_list, true ) ) {
if ( if (
@ -636,6 +636,13 @@ class MiniCart extends AbstractBlock {
*/ */
private function pattern_is_excluded( $context, $pattern_exclude_list ) { private function pattern_is_excluded( $context, $pattern_exclude_list ) {
$pattern_slug = is_array( $context ) && isset( $context['slug'] ) ? $context['slug'] : ''; $pattern_slug = is_array( $context ) && isset( $context['slug'] ) ? $context['slug'] : '';
if ( ! $pattern_slug ) {
/**
* Woo patterns have a slug property in $context, but core/theme patterns dont.
* In that case, we fallback to the name property, as they're the same.
*/
$pattern_slug = is_array( $context ) && isset( $context['name'] ) ? $context['name'] : '';
}
return in_array( $pattern_slug, $pattern_exclude_list, true ); return in_array( $pattern_slug, $pattern_exclude_list, true );
} }