From 64a505a8e11565f80e271cc233ffbeafe7618ef3 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 29 Mar 2023 10:53:01 -0500 Subject: [PATCH] Simplify __experimentalDuotone backwards compatibility --- .../get-global-styles-and-settings.php | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/lib/compat/wordpress-6.3/get-global-styles-and-settings.php b/lib/compat/wordpress-6.3/get-global-styles-and-settings.php index 1bdf1372075b7..5b4aebcaee34c 100644 --- a/lib/compat/wordpress-6.3/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.3/get-global-styles-and-settings.php @@ -47,31 +47,18 @@ function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = f $fallback_selector = $fallback ? $root_selector : null; - // Duotone ( may fallback to root selector ). - if ( 'filter.duotone' === $target || array( 'filter', 'duotone' ) === $target ) { - // If selectors API in use, only use it's value, fallback, or null. - if ( $has_selectors ) { - return _wp_array_get( $block_type->selectors, array( 'filter', 'duotone' ), $fallback_selector ); - } - - // Selectors API, not available, check for old experimental selector. - $duotone_selector = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null ); - - // Nothing to work with, provide fallback or null. - if ( null === $duotone_selector ) { - return $fallback_selector; - } - - // Scope the duotone selector by the block's root selector. - return WP_Theme_JSON_Gutenberg::scope_selector( $root_selector, $duotone_selector ); - } - - // If target is not `root` or `duotone` we have a feature or subfeature - // as the target. If the target is a string convert to an array. + // If target is not `root` we have a feature or subfeature as the target. + // If the target is a string convert to an array. if ( is_string( $target ) ) { $target = explode( '.', $target ); } + // Backwards compatibility for supports.__experimentalDuotone selectors when filter.duotone isn't set. + if ( array( 'filter', 'duotone' ) === $target && null === _wp_array_get( $block_type->selectors, $target ) ) { + $duotone_selector = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ) ); + return null === $duotone_selector ? null : WP_Theme_JSON_Gutenberg::scope_selector( $root_selector, $duotone_selector ); + } + // Feature Selectors ( may fallback to root selector ). if ( 1 === count( $target ) ) { // Prefer the selectors API if available.