Block selectors API: use whole selectors for duotone#49436
Conversation
The old API didn't have the whole selector, just parts of it, so we need to add the root.
|
Flaky tests detected in dac72ae. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4553951873
|
Before: .wp-duotone .wp-block-name After: .wp-duotone.wp-blockname
| $scopes = explode( ',', '.' . $filter_id ); | ||
| $selectors = explode( ',', $duotone_selector ); | ||
|
|
||
| $selectors_scoped = array(); |
There was a problem hiding this comment.
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:
- Create a utility
css_scope_selector( $scope, $selector )function somewhere and make it work like this code (no spaces added). - The consumer should be responsible for adding or not adding spaces:
css_scope_selector( $scope . ' ', $selector )if the consumer wants spaces.css_scope_selector( $scope . ' ', $selector )if the consumer doesn't want spaces.
Thoughts?
| $root_selectors = explode( ',', $root_selector ); | ||
| $duotone_selectors = explode( ',', $partial_duotone_selector ); | ||
|
|
||
| $duotone_selector = array(); |
There was a problem hiding this comment.
This could use the existing WP_Theme_JSON_Gutenberg::scope_selectors function, I guess. This function merits to be its own utility, given how much it has expanded: settings, duotone, WP_Theme_JSON class.
| "supports": { | ||
| "anchor": true, | ||
| "color": { | ||
| "__experimentalDuotone": true, |
There was a problem hiding this comment.
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.
I think this is needed to enable the filter controls in the block toolbar.
|
Closing in favor of #49423 |

What
Tentative fix for #49393 (comment)
Why
The Block Selectors API is meant to land in 15.5 but duotone works differently than any other selector. The global-level duotone style is also broken.
How
wp_get_block_css_selectorreturns the whole selector for duotone, even if the old API is in use 7f6b31dTODO
Test
selectors.filter.duotone) and two cover blocks (supports.color.__experimentalDuotone).purple-greenduotone for one of the images and one of the covers.The expected result is that the blocks with block-level duotone have it applied and the other ones use the global-level duotone in any context (front-end, post editor, site editor).
No other
imgelements of the page have any duotone applied (check the user avatar at the top-right, for example).