Repository navigation
Block Supports: Add PHP helpers for block support classes and styles - #14094
aaronrobertshaw wants to merge 13 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. |
a4d85e7 to
fee7818
Compare
|
I've been held up on some other priorities so this one will now be aimed for WP 7.3 |
fee7818 to
1d36d13
Compare
f8e168a to
3ebd5d1
Compare
… is null or empty.
…nd spacing helpers.
3ebd5d1 to
4020b55
Compare
|
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:
|
westonruter
left a comment
There was a problem hiding this comment.
I ran the changes to src through PHPStan level 10 and it reported back these opportunities for further refinement.
I added a suggestion to fix the issues in background.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
52 Cannot access offset 'background' on mixed.
🪪 offsetAccess.nonOffsetAccessible
184 Part $styles['style'] (mixed) of encapsed string cannot be cast to string.
🪪 encapsedStringPart.nonString
192 Parameter #1 $class_name of method WP_HTML_Tag_Processor::add_class() expects string, mixed given.
🪪 argument.type
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/border.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
65 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
70 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
70 Cannot access offset 'radius' on mixed.
🪪 offsetAccess.nonOffsetAccessible
74 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
74 Cannot access offset 'style' on mixed.
🪪 offsetAccess.nonOffsetAccessible
78 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
78 Cannot access offset 'width' on mixed.
🪪 offsetAccess.nonOffsetAccessible
82 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
82 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
87 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
87 Cannot access offset 'bottom'|'left'|'right'|'top' on mixed.
🪪 offsetAccess.nonOffsetAccessible
90 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
90 Cannot access offset 'bottom'|'left'|'right'|'top' on mixed.
🪪 offsetAccess.nonOffsetAccessible
99 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
99 Cannot access offset 'bottom'|'left'|'right'|'top' on mixed.
🪪 offsetAccess.nonOffsetAccessible
99 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
103 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
103 Cannot access offset 'bottom'|'left'|'right'|'top' on mixed.
🪪 offsetAccess.nonOffsetAccessible
103 Cannot access offset 'style' on mixed.
🪪 offsetAccess.nonOffsetAccessible
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
125 Cannot access offset 'border' on mixed.
🪪 offsetAccess.nonOffsetAccessible
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/colors.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
120 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
125 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
125 Cannot access offset 'text' on mixed.
🪪 offsetAccess.nonOffsetAccessible
129 Cannot access offset 'background' on mixed.
🪪 offsetAccess.nonOffsetAccessible
129 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
133 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
133 Cannot access offset 'gradient' on mixed.
🪪 offsetAccess.nonOffsetAccessible
137 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
137 Cannot access offset 'gradient' on mixed.
🪪 offsetAccess.nonOffsetAccessible
140 Parameter #2 $str of function explode expects string, mixed given.
🪪 argument.type
148 Function wp_apply_colors_support() should return array<string, mixed> but returns array.
🪪 return.type
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
178 Cannot access offset 'background'|'gradient'|'text' on mixed.
🪪 offsetAccess.nonOffsetAccessible
178 Cannot access offset 'color' on mixed.
🪪 offsetAccess.nonOffsetAccessible
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
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
81 Cannot access offset 'shadow' on mixed.
🪪 offsetAccess.nonOffsetAccessible
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/wp-includes/block-supports/spacing.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
52 Cannot access offset 'spacing' on mixed.
🪪 offsetAccess.nonOffsetAccessible
66 Cannot access offset 'margin' on mixed.
🪪 offsetAccess.nonOffsetAccessible
66 Cannot access offset 'spacing' on mixed.
🪪 offsetAccess.nonOffsetAccessible
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
87 Cannot access offset 'spacing' on mixed.
🪪 offsetAccess.nonOffsetAccessible
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 51 errors on changed lines (base: trunk @ 2f8310cf91)
|
Thanks for running this through level 10 @westonruter. I've added I've kept the The remaining errors are in the existing For anyone re-reviewing: Core's PHPStan check runs at level 5, which this PR passes. Level 10 only applies to the paths in So I've left the remaining |
Backport of Gutenberg PRs
Trac ticket: https://core.trac.wordpress.org/ticket/66269
Adds PHP helpers that turn block attributes into a block support's classes and styles, like the JS
get*ClassesAndStyles()functions, and moves the block supports onto them.This PR backports:
wp_get_border_classes_and_styles(),wp_get_shadow_classes_and_styles(),wp_get_spacing_classes_and_styles(),wp_get_color_classes_and_styles()andwp_get_background_classes_and_styles(),wp_apply_border_support(),wp_apply_shadow_support(),wp_apply_spacing_support(),wp_apply_colors_support()andwp_render_background_support()built on them,The block changes that call these helpers (Avatar, Post Featured Image, Icon, Post Navigation Link, Navigation Submenu, Comment Author Avatar, Calendar and Button) arrive later with the Gutenberg package update.
Testing instructions
The block support output should be identical to trunk. The one exception: a null, false, empty or zero preset color now falls back to the custom color, as in JS. To compare, register a dynamic test block and render it on trunk and on this branch:
Both branches output:
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.