Repository navigation
Editor: Apply duotone presets with slugs that are not kebab-case on the front end - #14188
maheshbohara wants to merge 1 commit into
Conversation
…he front end. `WP_Duotone` registers presets under a kebab-cased filter ID, but used the raw slug when reading the preset from a block attribute and when naming the CSS custom property. A preset with a slug such as `blueOrange` was therefore not recognized when applied to a block, and its custom property did not match the kebab-cased reference when applied through global styles. This converts the slug to kebab-case in `WP_Duotone::get_slug_from_attribute()` and `WP_Duotone::get_global_styles_presets()`, so the class name, SVG filter ID, CSS custom property, and block CSS all use the same form. Slugs that are already kebab-case are unchanged. Follow-up to [56101], [63641]. See #66285.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
A duotone preset whose slug is not already kebab-case (for example
blueOrangeorduotone1) works in the block editor but is not applied on the front end.WP_Duotone::get_all_global_styles_presets()registers presets under a kebab-cased filter ID, but two other places use the raw slug:get_slug_from_attribute()returns the slug exactly as written in the block attribute, so the lookup inis_preset()fails.get_global_styles_presets()names the CSS custom property after the raw slug.This PR converts the slug to kebab-case in both, so the class name, SVG filter ID, CSS custom property and block CSS all use the same form. Slugs that are already kebab-case are unchanged.
Before
Preset
blueOrangeapplied to an Image block (var:preset|duotone|blueOrange): the preset is not recognised, the attribute is treated as a raw CSS value, and no SVG filter is printed.The same preset applied through global styles: since [63641] the reference is kebab-cased, but the custom property is still defined with the raw slug, so it never resolves.
After
and
<filter id="wp-duotone-blue-orange">is printed in the footer.Testing
theme.json, add a duotone preset with a camelCase slug:Unit tests:
The new
test_render_duotone_support_preset_with_non_kebab_case_slugcovers a camelCase slug referenced both ways, a slug with a trailing number, and a kebab-case slug as a control. New cases were also added to theget_slug_from_attributeandis_presetdata providers.One existing expectation changed: a reference whose slug is only
.now yields an empty slug instead of., because kebab-casing removes it. It was not a valid preset before either.Note
lib/class-wp-duotone-gutenberg.phpin the Gutenberg plugin has the same two lines and would need the same change.Trac ticket: https://core.trac.wordpress.org/ticket/66285
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus
Used for: Investigating and reproducing the bug, and drafting the patch, unit tests and this description. I reviewed the changes and ran the tests locally.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.