Repository navigation
Block Supports: Add a helper that returns every support's classes and styles - #15485
aaronrobertshaw wants to merge 3 commits into
Conversation
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. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
ramonjd
left a comment
There was a problem hiding this comment.
Backport is accurate. I smoke tested a bunch of blocks on the frontend, checked the CSS and classnames.
Tests pass locally.
Might be worth holding off until 7.2 is stable to avoid clashes?
Thanks!
westonruter
left a comment
There was a problem hiding this comment.
As with #14094 (review), I ran the changes to src through PHPStan level 8 and it reported back these opportunities for further refinement.
I added a suggestion to fix the issues in border.php.
The report:
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/background.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
47 Function wp_get_background_classes_and_styles() has parameter $block_attributes with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
47 Function wp_get_background_classes_and_styles() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/border.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
120 Function wp_get_border_classes_and_styles() has parameter $block_attributes with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
120 Function wp_get_border_classes_and_styles() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/colors.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
161 Function wp_get_color_classes_and_styles() has parameter $block_attributes with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
161 Function wp_get_color_classes_and_styles() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/shadow.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
76 Function wp_get_shadow_classes_and_styles() has parameter $block_attributes with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
76 Function wp_get_shadow_classes_and_styles() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/spacing.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
82 Function wp_get_spacing_classes_and_styles() has parameter $block_attributes with no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
82 Function wp_get_spacing_classes_and_styles() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
🪪 missingType.iterableValue
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 10 errors on changed lines (base: trunk @ 2f8310cf91)
a2621d6 to
986ab3c
Compare
|
Thanks @westonruter. The Would you mind taking another look at both PRs? |
… styles. Adds wp_get_block_supports_classes_and_styles(), which combines the background, color, border, shadow and spacing helpers in the style engine's order. An optional list limits it to the supports a block applies to one element.
986ab3c to
aa2f1d5
Compare
|
#14094 is now committed in r65798, and this PR has been rebased accordingly. The diff now only has the new @westonruter unless you have concerns with that function, could you approve or dismiss your review so I can commit this one? 7.2 has branched, so Ramon's note about waiting is covered too. |
| * Default null, for all of them. | ||
| * @return array<string, string> Array with `class` and `style` keys, each present only when non-empty. | ||
| * | ||
| * @phpstan-return array{ class?: non-empty-string, style?: non-empty-string } |
There was a problem hiding this comment.
Bonus:
| * @phpstan-return array{ class?: non-empty-string, style?: non-empty-string } | |
| * @phpstan-param array<'background'|'color'|'border'|'shadow'|'spacing'>|null $supports | |
| * @phpstan-return array{ class?: non-empty-string, style?: non-empty-string } |
Backport of Gutenberg PR WordPress/gutenberg#86337
Trac ticket: https://core.trac.wordpress.org/ticket/66485
Adds
wp_get_block_supports_classes_and_styles(), which returns the combined classes and styles of the background, color, border, shadow and spacing helpers. An optional list limits it to the supports a block applies to one element.This PR backports:
wp_get_block_supports_classes_and_styles(), next to the other block support utilities,The Avatar and Post Navigation Link changes that call it arrive later with the Gutenberg package update.
Builds on the helpers committed in r65798 for #14094.
Testing instructions
Nothing renders differently, because no block calls the helper in Core yet. To check its output:
It outputs only the border and shadow, without the padding:
Without this PR the command fails with a fatal error for an undefined function.
Use of AI
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: the port from Gutenberg and the tests; I reviewed and edited them.