-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block selectors API: use whole selectors for duotone #49436
Changes from all commits
17ab41d
7f6b31d
8fc3110
dac72ae
70198b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,6 @@ function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = f | |
|
||
$has_selectors = ! empty( $block_type->selectors ); | ||
|
||
// Duotone (No fallback selectors for Duotone). | ||
if ( 'filter.duotone' === $target || array( 'filter', 'duotone' ) === $target ) { | ||
// If selectors API in use, only use it's value or null. | ||
if ( $has_selectors ) { | ||
return _wp_array_get( $block_type->selectors, array( 'filter', 'duotone' ), null ); | ||
} | ||
|
||
// Selectors API, not available, check for old experimental selector. | ||
return _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null ); | ||
} | ||
|
||
// Root Selector. | ||
|
||
// Calculated before returning as it can be used as fallback for | ||
|
@@ -54,6 +43,39 @@ function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = f | |
$root_selector = ".wp-block-{$block_name}"; | ||
} | ||
|
||
// Duotone (No fallback selectors for Duotone). | ||
if ( 'filter.duotone' === $target || array( 'filter', 'duotone' ) === $target ) { | ||
// If selectors API in use, only use it's value or null. | ||
if ( $has_selectors ) { | ||
return _wp_array_get( $block_type->selectors, array( 'filter', 'duotone' ), null ); | ||
} | ||
|
||
// Selectors API, not available, check for old experimental selector. | ||
// The old API didn't have the whole selector, just parts of it, | ||
// so we need to add the root here for backwards compatibility. | ||
$partial_duotone_selector = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null ); | ||
|
||
$root_selectors = explode( ',', $root_selector ); | ||
$duotone_selectors = explode( ',', $partial_duotone_selector ); | ||
|
||
$duotone_selector = array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use the existing |
||
foreach ( $root_selectors as $outer ) { | ||
foreach ( $duotone_selectors as $inner ) { | ||
$outer = trim( $outer ); | ||
$inner = trim( $inner ); | ||
if ( ! empty( $outer ) && ! empty( $inner ) ) { | ||
$duotone_selector[] = $outer . ' ' . $inner; | ||
} elseif ( empty( $outer ) ) { | ||
$duotone_selector[] = $inner; | ||
} elseif ( empty( $inner ) ) { | ||
$duotone_selector[] = $outer; | ||
} | ||
} | ||
} | ||
|
||
return implode( ', ', $duotone_selector ); | ||
} | ||
|
||
// Return selector if it's the root target we are looking for. | ||
if ( 'root' === $target ) { | ||
return $root_selector; | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -85,7 +85,6 @@ | |||
"supports": { | ||||
"anchor": true, | ||||
"color": { | ||||
"__experimentalDuotone": true, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something I found by reviewing the duotone code (not related to this PR): gutenberg/lib/class-wp-duotone-gutenberg.php Line 281 in 70198b9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is needed to enable the filter controls in the block toolbar. |
||||
"text": false, | ||||
"background": false | ||||
}, | ||||
|
@@ -104,7 +103,7 @@ | |||
"selectors": { | ||||
"border": ".wp-block-image img, .wp-block-image .wp-block-image__crop-area", | ||||
"filter": { | ||||
"duotone": "img, .components-placeholder" | ||||
"duotone": ".wp-block-image img, .wp-block-image .components-placeholder" | ||||
} | ||||
}, | ||||
"styles": [ | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I hadn't to paste this here, but I need this to work differently than the
WP_Theme_JSON_Gutenberg::scope_selector
.Ideas for a follow-up PR:
css_scope_selector( $scope, $selector )
function somewhere and make it work like this code (no spaces added).css_scope_selector( $scope . ' ', $selector )
if the consumer wants spaces.css_scope_selector( $scope . ' ', $selector )
if the consumer doesn't want spaces.Thoughts?