Repository navigation
Colour: Add a PHP helper for block support classes and styles - #84206
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.61 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
871f822 to
30eecbf
Compare
39ad58f to
884c378
Compare
7ead1ca to
0c0ad39
Compare
5157112 to
ebd42f6
Compare
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for the follow-up.
In my testing, the calendar block uses the same color code as the block support instead of keeping its own copy, and the output matches trunk in my testing.
Just left a couple of questions about the numeric checks on the slugs. Not sure if they're required?
c94e83f to
a4e7ab4
Compare
|
Thanks for the reviews @ramonjd 👍 I've addressed the feedback to date and applied some of that across all the PHP block support helper PRs I have open. PHPStan also landed on trunk this week and doesn't know the new helper yet since it isn't in Core until WordPress/wordpress-develop#14094. So I've added a temporary baseline entry for it. I'll look to get these PRs merged and juggle the rebases needed for that today and tomorrow. |
bcda3fa to
aade5ad
Compare
Theme.json slugs are strings and the editor always coerces them, so the numeric and boolean handling only added code.
The block library calls wp_get_color_classes_and_styles(), which the build prefixes to gutenberg_get_color_classes_and_styles() for the plugin, but which PHPStan resolves from the WordPress stubs. The stubs were generated from core trunk, which lacks the function, so its call was baselined as not found. Generate the stubs from wordpress-develop PR 14094, which backports the helper, and drop the baselined error. Regenerate them from trunk once the backport is committed. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: cfcf15e8-ccc1-4d78-a7c9-51f73e8e4b92
This reverts commit 09c0e68.
…n until the stubs include it
fa4a46a to
8130a1d
Compare
Follows up on #83122.
Core backport: wordpress-develop#14094.
What?
Adds a shared PHP helper that turns a block's color attributes into classes and inline styles, the PHP version of the JS
getColorClassesAndStyles().The color block support and Calendar now use it.
Why?
Calendar skips color serialization so it can put its colors on the table. It copies the block support's text and background logic to do so. A shared helper keeps the two in step.
How?
The helper only builds output. It doesn't check what a block supports, so each caller passes in the values it applies.
has-link-colorclassprefixFunctions, so the plugin callsgutenberg_get_color_classes_and_styles()The only output change: a null, false, empty or zero preset attribute now falls back to the custom color, as in JS. So does an array, which cannot form a class name.
PHPStan's WordPress stubs are built from Core trunk, which won't have this helper until wordpress-develop#14094 lands. So this PR adds a temporary baseline entry for it. PHPStan will flag the entry for removal once the stubs move to a Core trunk with the helper.
Testing Instructions
Use of AI Tools
Implemented and tested by a Claude Code agent from a predefined task.