Skip to content

Commit

Permalink
Simplify __experimentalDuotone backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lende authored and oandregal committed Mar 29, 2023
1 parent 555f7d0 commit 64a505a
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions lib/compat/wordpress-6.3/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 64a505a

Please sign in to comment.