From e01a6030efd2b8ebcc975af1264c8dd85495948a Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 8 Oct 2026 08:20:12 +0800
Subject: [PATCH 01/13] Spacing: Add a PHP helper for block support classes and
styles
---
lib/block-supports/spacing.php | 39 ++++++-
packages/block-library/package.json | 3 +-
.../src/comment-author-avatar/index.php | 17 +--
packages/block-library/src/icon/index.php | 19 ++--
.../src/post-navigation-link/index.php | 9 +-
phpunit/block-supports/spacing-test.php | 107 ++++++++++++++++++
...ender-block-comment-author-avatar-test.php | 94 +++++++++++++++
phpunit/blocks/render-block-icon-test.php | 33 ++++++
...render-block-post-navigation-link-test.php | 13 +++
9 files changed, 300 insertions(+), 34 deletions(-)
create mode 100644 phpunit/blocks/render-block-comment-author-avatar-test.php
diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php
index d5d5f1777030fd..7d8b8c52df4cf0 100644
--- a/lib/block-supports/spacing.php
+++ b/lib/block-supports/spacing.php
@@ -54,17 +54,46 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
$skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
$skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
- $spacing_block_styles = array(
- 'padding' => null,
- 'margin' => null,
- );
+ $spacing_block_styles = array();
if ( $has_padding_support && ! $skip_padding ) {
$spacing_block_styles['padding'] = $block_styles['spacing']['padding'] ?? null;
}
if ( $has_margin_support && ! $skip_margin ) {
$spacing_block_styles['margin'] = $block_styles['spacing']['margin'] ?? null;
}
- $styles = gutenberg_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
+
+ return gutenberg_get_spacing_classes_and_styles( array( 'style' => array( 'spacing' => $spacing_block_styles ) ) );
+}
+
+/**
+ * Gets the spacing CSS classes and inline styles for the given block
+ * attributes. The PHP twin of the JS `getSpacingClassesAndStyles()`.
+ *
+ * @since 7.2.0
+ *
+ * @param array $block_attributes Block attributes.
+ *
+ * @return array Spacing CSS classes and inline styles.
+ */
+function gutenberg_get_spacing_classes_and_styles( $block_attributes ) {
+ $spacing = $block_attributes['style']['spacing'] ?? null;
+ if ( ! is_array( $spacing ) ) {
+ return array();
+ }
+
+ $styles = gutenberg_style_engine_get_styles(
+ array(
+ 'spacing' => array(
+ 'padding' => $spacing['padding'] ?? null,
+ 'margin' => $spacing['margin'] ?? null,
+ ),
+ )
+ );
+ $attributes = array();
+
+ if ( ! empty( $styles['classnames'] ) ) {
+ $attributes['class'] = $styles['classnames'];
+ }
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
diff --git a/packages/block-library/package.json b/packages/block-library/package.json
index 6c5d72e36a963c..6e7eb6d0554dd8 100644
--- a/packages/block-library/package.json
+++ b/packages/block-library/package.json
@@ -75,7 +75,8 @@
"wp_get_shadow_classes_and_styles",
"wp_style_engine_get_styles",
"wp_get_global_styles",
- "wp_get_global_settings"
+ "wp_get_global_settings",
+ "wp_get_spacing_classes_and_styles"
],
"suffixClasses": [
"WP_Navigation_Block_Renderer"
diff --git a/packages/block-library/src/comment-author-avatar/index.php b/packages/block-library/src/comment-author-avatar/index.php
index 87e28e64b81eb7..3ad1a9e8e71c72 100644
--- a/packages/block-library/src/comment-author-avatar/index.php
+++ b/packages/block-library/src/comment-author-avatar/index.php
@@ -26,20 +26,9 @@ function render_block_core_comment_author_avatar( $attributes, $content, $block
// This is the only way to retrieve style and classes on different instances.
$wrapper_attributes = WP_Block_Supports::get_instance()->apply_block_supports();
- /**
- * We get the spacing attributes and transform the array provided into a string formatted for being applied as a style html tag.
- * Good candidate to be moved to a separate function in core.
- */
+ // Spacing skips serialization, so it is applied to the wrapper rather than the image.
$spacing_attributes = $attributes['style']['spacing'] ?? null;
- if ( isset( $spacing_attributes ) && ! empty( $spacing_attributes ) ) {
- $spacing_array = array();
- foreach ( $spacing_attributes as $spacing_attribute_key => $spacing_attribute_value ) {
- foreach ( $spacing_attribute_value as $position_key => $position_value ) {
- $spacing_array[] = $spacing_attribute_key . '-' . $position_key . ': ' . $position_value;
- }
- }
- $spacing_string = implode( ';', $spacing_array );
- }
+ $spacing_styles = wp_get_spacing_classes_and_styles( $attributes );
$width = $attributes['width'] ?? 96;
$height = $attributes['height'] ?? 96;
@@ -62,7 +51,7 @@ function render_block_core_comment_author_avatar( $attributes, $content, $block
)
);
if ( isset( $spacing_attributes ) ) {
- return sprintf( '
%2$s
', esc_attr( $spacing_string ), $avatar_block );
+ return sprintf( '%2$s
', esc_attr( $spacing_styles['style'] ?? '' ), $avatar_block );
}
return sprintf( '%s
', $avatar_block );
}
diff --git a/packages/block-library/src/icon/index.php b/packages/block-library/src/icon/index.php
index fe1734b7e30f5f..8652eabffdd1b7 100644
--- a/packages/block-library/src/icon/index.php
+++ b/packages/block-library/src/icon/index.php
@@ -86,12 +86,6 @@ function render_block_core_icon( $attributes ) {
// Shadow.
$shadow_styles = $attributes['style']['shadow'] ?? null;
- // Spacing (Padding).
- $spacing_styles = array();
- if ( isset( $attributes['style']['spacing']['padding'] ) ) {
- $spacing_styles['padding'] = $attributes['style']['spacing']['padding'];
- }
-
// Dimensions (Width, Min width, Min height).
$dimensions_styles = array();
foreach ( array( 'width', 'minWidth', 'minHeight' ) as $dimension ) {
@@ -101,16 +95,25 @@ function render_block_core_icon( $attributes ) {
}
// Generate styles and classes.
- $styles = wp_style_engine_get_styles(
+ $styles = wp_style_engine_get_styles(
array(
'color' => $color_styles,
'background' => $background_styles,
'border' => $border_styles,
'shadow' => $shadow_styles,
- 'spacing' => $spacing_styles,
'dimensions' => $dimensions_styles,
),
);
+ $spacing_styles = wp_get_spacing_classes_and_styles(
+ array(
+ 'style' => array(
+ 'spacing' => array(
+ 'padding' => $attributes['style']['spacing']['padding'] ?? null,
+ ),
+ ),
+ )
+ );
+ $styles['css'] = ( $styles['css'] ?? '' ) . ( $spacing_styles['style'] ?? '' );
$svg = wp_get_icon(
$attributes['icon'],
diff --git a/packages/block-library/src/post-navigation-link/index.php b/packages/block-library/src/post-navigation-link/index.php
index 047b05d42d756d..7a4f4d75967908 100644
--- a/packages/block-library/src/post-navigation-link/index.php
+++ b/packages/block-library/src/post-navigation-link/index.php
@@ -215,7 +215,7 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) {
}
}
- $styles = wp_style_engine_get_styles(
+ $styles = wp_style_engine_get_styles(
array(
'background' => $background_styles,
'border' => $border_styles,
@@ -224,12 +224,9 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) {
'minWidth' => $block_styles['dimensions']['minWidth'] ?? null,
),
'shadow' => $block_styles['shadow'] ?? null,
- 'spacing' => array(
- 'margin' => $block_styles['spacing']['margin'] ?? null,
- 'padding' => $block_styles['spacing']['padding'] ?? null,
- ),
)
);
+ $spacing_styles = wp_get_spacing_classes_and_styles( $attributes );
$class_names = $styles['classnames'] ?? '';
@@ -240,7 +237,7 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) {
return array(
'class' => $class_names,
- 'style' => $styles['css'] ?? '',
+ 'style' => ( $styles['css'] ?? '' ) . ( $spacing_styles['style'] ?? '' ),
);
}
diff --git a/phpunit/block-supports/spacing-test.php b/phpunit/block-supports/spacing-test.php
index fd66d7b22ec434..300881eb4096e2 100644
--- a/phpunit/block-supports/spacing-test.php
+++ b/phpunit/block-supports/spacing-test.php
@@ -157,4 +157,111 @@ public function test_margin_with_individual_skipped_serialization_block_supports
$this->assertSame( $expected, $actual );
}
+
+ /**
+ * @dataProvider data_get_spacing_classes_and_styles
+ *
+ * @covers ::gutenberg_get_spacing_classes_and_styles
+ *
+ * @param mixed $block_attributes Block attributes.
+ * @param array $expected Expected classes and styles.
+ */
+ public function test_get_spacing_classes_and_styles( $block_attributes, $expected ) {
+ $this->assertSame( $expected, gutenberg_get_spacing_classes_and_styles( $block_attributes ) );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array
+ */
+ public function data_get_spacing_classes_and_styles() {
+ return array(
+ 'custom values' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => array(
+ 'padding' => array(
+ 'top' => '1px',
+ 'left' => '2em',
+ ),
+ 'margin' => '3px',
+ ),
+ ),
+ ),
+ 'expected' => array(
+ 'style' => 'padding-top:1px;padding-left:2em;margin:3px;',
+ ),
+ ),
+ 'presets' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => array(
+ 'padding' => 'var:preset|spacing|40',
+ 'margin' => array( 'bottom' => 'var:preset|spacing|20' ),
+ ),
+ ),
+ ),
+ 'expected' => array(
+ 'style' => 'padding:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--20);',
+ ),
+ ),
+ 'block gap is ignored' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => array( 'blockGap' => '2em' ),
+ ),
+ ),
+ 'expected' => array(),
+ ),
+ 'numeric values' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => array( 'padding' => array( 'top' => 10 ) ),
+ ),
+ ),
+ 'expected' => array(),
+ ),
+ 'zero' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => array( 'margin' => '0' ),
+ ),
+ ),
+ 'expected' => array(
+ 'style' => 'margin:0;',
+ ),
+ ),
+ 'empty spacing' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => array(),
+ ),
+ ),
+ 'expected' => array(),
+ ),
+ 'no style' => array(
+ 'block_attributes' => array(),
+ 'expected' => array(),
+ ),
+ 'malformed spacing' => array(
+ 'block_attributes' => array(
+ 'style' => array(
+ 'spacing' => '10px',
+ ),
+ ),
+ 'expected' => array(),
+ ),
+ 'malformed style' => array(
+ 'block_attributes' => array(
+ 'style' => 'padding:10px',
+ ),
+ 'expected' => array(),
+ ),
+ 'malformed attributes' => array(
+ 'block_attributes' => null,
+ 'expected' => array(),
+ ),
+ );
+ }
}
diff --git a/phpunit/blocks/render-block-comment-author-avatar-test.php b/phpunit/blocks/render-block-comment-author-avatar-test.php
new file mode 100644
index 00000000000000..ab6570d2191ade
--- /dev/null
+++ b/phpunit/blocks/render-block-comment-author-avatar-test.php
@@ -0,0 +1,94 @@
+post->create();
+ self::$comment_id = $factory->comment->create(
+ array(
+ 'comment_post_ID' => $post_id,
+ 'comment_author' => 'Test',
+ 'comment_author_email' => 'test@example.org',
+ )
+ );
+ }
+
+ /**
+ * Renders a Comment Author Avatar block and returns its wrapper style.
+ *
+ * @param array $attributes Block attributes.
+ * @return string|null Wrapper `style` attribute.
+ */
+ private function get_wrapper_style( $attributes ) {
+ $parsed_block = parse_blocks( '' )[0];
+ $block = new WP_Block( $parsed_block, array( 'commentId' => self::$comment_id ) );
+
+ $processor = new WP_HTML_Tag_Processor( $block->render() );
+ $this->assertTrue( $processor->next_tag( 'div' ) );
+
+ return $processor->get_attribute( 'style' );
+ }
+
+ /**
+ * @dataProvider data_spacing_styles
+ *
+ * @param array $spacing Spacing attribute.
+ * @param string $expected_style Expected wrapper style.
+ */
+ public function test_wrapper_has_spacing_styles( $spacing, $expected_style ) {
+ $this->assertSame( $expected_style, $this->get_wrapper_style( array( 'style' => array( 'spacing' => $spacing ) ) ) );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array
+ */
+ public function data_spacing_styles() {
+ return array(
+ 'custom value' => array(
+ 'spacing' => array( 'padding' => array( 'top' => '10px' ) ),
+ 'expected_style' => 'padding-top:10px;',
+ ),
+ 'preset' => array(
+ 'spacing' => array( 'padding' => array( 'top' => 'var:preset|spacing|40' ) ),
+ 'expected_style' => 'padding-top:var(--wp--preset--spacing--40);',
+ ),
+ 'padding and margin' => array(
+ 'spacing' => array(
+ 'margin' => array( 'top' => '5px' ),
+ 'padding' => array( 'left' => '10px' ),
+ ),
+ 'expected_style' => 'padding-left:10px;margin-top:5px;',
+ ),
+ 'empty spacing array' => array(
+ 'spacing' => array(),
+ 'expected_style' => '',
+ ),
+ );
+ }
+
+ public function test_wrapper_has_no_style_without_spacing() {
+ $this->assertNull( $this->get_wrapper_style( array() ) );
+ }
+}
diff --git a/phpunit/blocks/render-block-icon-test.php b/phpunit/blocks/render-block-icon-test.php
index c24f7605911683..a24a9ebfb657eb 100644
--- a/phpunit/blocks/render-block-icon-test.php
+++ b/phpunit/blocks/render-block-icon-test.php
@@ -108,6 +108,39 @@ public function test_shadow_keeps_the_style_engine_order() {
$this->assertSame( 'fill: none; color:#000;border-width:2px;box-shadow:var(--wp--preset--shadow--natural);width:48px;padding:4px;', $processor->get_attribute( 'style' ) );
}
+ public function test_applies_color_border_width_and_padding_styles() {
+ $output = gutenberg_render_block_core_icon(
+ array(
+ 'icon' => 'core/caution',
+ 'textColor' => 'accent',
+ 'style' => array(
+ 'color' => array( 'background' => '#ffeeee' ),
+ 'border' => array(
+ 'radius' => '4px',
+ 'width' => '2px',
+ 'style' => 'solid',
+ 'color' => '#000000',
+ ),
+ 'dimensions' => array( 'width' => '48px' ),
+ 'spacing' => array(
+ 'padding' => array(
+ 'top' => 'var:preset|spacing|20',
+ 'left' => '8px',
+ ),
+ ),
+ ),
+ )
+ );
+
+ $processor = new WP_HTML_Tag_Processor( $output );
+ $this->assertTrue( $processor->next_tag( 'svg' ) );
+ $this->assertSame( 'has-text-color has-accent-color has-background has-border-color', $processor->get_attribute( 'class' ) );
+ $this->assertSame(
+ 'fill: none; color:var(--wp--preset--color--accent);background-color:#ffeeee;border-color:#000000;border-radius:4px;border-style:solid;border-width:2px;width:48px;padding-top:var(--wp--preset--spacing--20);padding-left:8px;',
+ $processor->get_attribute( 'style' )
+ );
+ }
+
public function test_renders_only_icons_in_public_collections() {
// Renders public core icon.
$processor = new WP_HTML_Tag_Processor( gutenberg_render_block_core_icon( array( 'icon' => 'core/caution' ) ) );
diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php
index 3acba75ea1c37e..71aa769352d956 100644
--- a/phpunit/blocks/render-block-post-navigation-link-test.php
+++ b/phpunit/blocks/render-block-post-navigation-link-test.php
@@ -127,6 +127,19 @@ public function test_rendered_link_includes_border_dimensions_shadow_and_spacing
$this->assertStringContainsString( 'has-accent-2-border-color', $output );
}
+ public function test_rendered_link_has_the_full_border_shadow_and_spacing_styles() {
+ $attributes = $this->styled_attributes();
+ $attributes['style']['spacing']['margin']['top'] = 'var:preset|spacing|30';
+
+ $processor = new WP_HTML_Tag_Processor( $this->render_block( self::$second_post_id, $attributes ) );
+ $this->assertTrue( $processor->next_tag( 'div' ) );
+ $this->assertSame( 'post-navigation-link-previous has-border-color has-accent-2-border-color wp-block-post-navigation-link', $processor->get_attribute( 'class' ) );
+ $this->assertSame(
+ 'border-style:dashed;border-width:3px;box-shadow:10px 10px 5px #000000;padding-top:20px;margin-top:var(--wp--preset--spacing--30)',
+ $processor->get_attribute( 'style' )
+ );
+ }
+
public function test_individual_border_sides_match_the_core_declaration_order() {
$attributes = array(
'type' => 'previous',
From bd51fbdd6f5247372665c5007ec32df7b25f2c12 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 8 Oct 2026 14:11:21 +0800
Subject: [PATCH 02/13] Address review feedback
---
lib/block-supports/spacing.php | 8 ++++----
packages/block-library/package.json | 4 ++--
.../block-library/src/comment-author-avatar/index.php | 9 ++++-----
phpunit/block-supports/spacing-test.php | 4 ----
.../blocks/render-block-comment-author-avatar-test.php | 4 ++--
.../blocks/render-block-post-navigation-link-test.php | 2 +-
6 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php
index 7d8b8c52df4cf0..5abf6aa3ad4198 100644
--- a/lib/block-supports/spacing.php
+++ b/lib/block-supports/spacing.php
@@ -66,14 +66,14 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
}
/**
- * Gets the spacing CSS classes and inline styles for the given block
- * attributes. The PHP twin of the JS `getSpacingClassesAndStyles()`.
+ * Returns spacing classes and inline styles for block attributes, like the JS
+ * `getSpacingClassesAndStyles()`. Does not check block support or skipped
+ * serialization.
*
* @since 7.2.0
*
* @param array $block_attributes Block attributes.
- *
- * @return array Spacing CSS classes and inline styles.
+ * @return array Array with `class` and `style` keys, each present only when non-empty.
*/
function gutenberg_get_spacing_classes_and_styles( $block_attributes ) {
$spacing = $block_attributes['style']['spacing'] ?? null;
diff --git a/packages/block-library/package.json b/packages/block-library/package.json
index 6e7eb6d0554dd8..06ede8f1e8724f 100644
--- a/packages/block-library/package.json
+++ b/packages/block-library/package.json
@@ -74,9 +74,9 @@
"wp_get_typography_font_size_value",
"wp_get_shadow_classes_and_styles",
"wp_style_engine_get_styles",
+ "wp_get_spacing_classes_and_styles",
"wp_get_global_styles",
- "wp_get_global_settings",
- "wp_get_spacing_classes_and_styles"
+ "wp_get_global_settings"
],
"suffixClasses": [
"WP_Navigation_Block_Renderer"
diff --git a/packages/block-library/src/comment-author-avatar/index.php b/packages/block-library/src/comment-author-avatar/index.php
index 3ad1a9e8e71c72..297d5e273aeea5 100644
--- a/packages/block-library/src/comment-author-avatar/index.php
+++ b/packages/block-library/src/comment-author-avatar/index.php
@@ -26,10 +26,6 @@ function render_block_core_comment_author_avatar( $attributes, $content, $block
// This is the only way to retrieve style and classes on different instances.
$wrapper_attributes = WP_Block_Supports::get_instance()->apply_block_supports();
- // Spacing skips serialization, so it is applied to the wrapper rather than the image.
- $spacing_attributes = $attributes['style']['spacing'] ?? null;
- $spacing_styles = wp_get_spacing_classes_and_styles( $attributes );
-
$width = $attributes['width'] ?? 96;
$height = $attributes['height'] ?? 96;
$styles = $wrapper_attributes['style'] ?? '';
@@ -50,7 +46,10 @@ function render_block_core_comment_author_avatar( $attributes, $content, $block
'class' => $classes,
)
);
- if ( isset( $spacing_attributes ) ) {
+
+ // Spacing skips serialization, so it goes on the outer div, not the image.
+ if ( isset( $attributes['style']['spacing'] ) ) {
+ $spacing_styles = wp_get_spacing_classes_and_styles( $attributes );
return sprintf( '%2$s
', esc_attr( $spacing_styles['style'] ?? '' ), $avatar_block );
}
return sprintf( '%s
', $avatar_block );
diff --git a/phpunit/block-supports/spacing-test.php b/phpunit/block-supports/spacing-test.php
index 300881eb4096e2..5c1ad9ee5c4ab3 100644
--- a/phpunit/block-supports/spacing-test.php
+++ b/phpunit/block-supports/spacing-test.php
@@ -258,10 +258,6 @@ public function data_get_spacing_classes_and_styles() {
),
'expected' => array(),
),
- 'malformed attributes' => array(
- 'block_attributes' => null,
- 'expected' => array(),
- ),
);
}
}
diff --git a/phpunit/blocks/render-block-comment-author-avatar-test.php b/phpunit/blocks/render-block-comment-author-avatar-test.php
index ab6570d2191ade..7330e7e853f633 100644
--- a/phpunit/blocks/render-block-comment-author-avatar-test.php
+++ b/phpunit/blocks/render-block-comment-author-avatar-test.php
@@ -52,8 +52,8 @@ private function get_wrapper_style( $attributes ) {
/**
* @dataProvider data_spacing_styles
*
- * @param array $spacing Spacing attribute.
- * @param string $expected_style Expected wrapper style.
+ * @param array $spacing Spacing attribute.
+ * @param string $expected_style Expected wrapper style.
*/
public function test_wrapper_has_spacing_styles( $spacing, $expected_style ) {
$this->assertSame( $expected_style, $this->get_wrapper_style( array( 'style' => array( 'spacing' => $spacing ) ) ) );
diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php
index 71aa769352d956..6a4686a3920ff3 100644
--- a/phpunit/blocks/render-block-post-navigation-link-test.php
+++ b/phpunit/blocks/render-block-post-navigation-link-test.php
@@ -127,7 +127,7 @@ public function test_rendered_link_includes_border_dimensions_shadow_and_spacing
$this->assertStringContainsString( 'has-accent-2-border-color', $output );
}
- public function test_rendered_link_has_the_full_border_shadow_and_spacing_styles() {
+ public function test_border_shadow_and_spacing_styles() {
$attributes = $this->styled_attributes();
$attributes['style']['spacing']['margin']['top'] = 'var:preset|spacing|30';
From 9069c42e714878831c196f9be3a299a4c5bca686 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 8 Oct 2026 15:09:16 +0800
Subject: [PATCH 03/13] Add backport changelog entry
---
backport-changelog/7.2/14094.md | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 backport-changelog/7.2/14094.md
diff --git a/backport-changelog/7.2/14094.md b/backport-changelog/7.2/14094.md
new file mode 100644
index 00000000000000..af2f1e32bd6b82
--- /dev/null
+++ b/backport-changelog/7.2/14094.md
@@ -0,0 +1,7 @@
+https://github.com/WordPress/wordpress-develop/pull/14094
+
+* https://github.com/WordPress/gutenberg/pull/84205
+* https://github.com/WordPress/gutenberg/pull/84206
+* https://github.com/WordPress/gutenberg/pull/84207
+* https://github.com/WordPress/gutenberg/pull/84208
+* https://github.com/WordPress/gutenberg/pull/84209
From 90558ad742694d6f2ee43a008874ff2d20bdb301 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 8 Oct 2026 21:18:55 +0800
Subject: [PATCH 04/13] Filter by removing values before calling the helper
---
lib/block-supports/spacing.php | 31 ++++++++------
phpunit/block-supports/spacing-test.php | 57 +++++++++++++++++++++++++
2 files changed, 74 insertions(+), 14 deletions(-)
diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php
index 5abf6aa3ad4198..d5c2c1d5c243ab 100644
--- a/lib/block-supports/spacing.php
+++ b/lib/block-supports/spacing.php
@@ -43,26 +43,29 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
return array();
}
- $attributes = array();
- $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
- $has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false );
- $block_styles = $block_attributes['style'] ?? null;
+ if ( empty( $block_attributes['style'] ) ) {
+ return array();
+ }
- if ( ! $block_styles ) {
- return $attributes;
+ $attributes = $block_attributes;
+ if ( ! is_array( $attributes['style']['spacing'] ?? null ) ) {
+ return array();
}
- $skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
- $skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
- $spacing_block_styles = array();
- if ( $has_padding_support && ! $skip_padding ) {
- $spacing_block_styles['padding'] = $block_styles['spacing']['padding'] ?? null;
+ if (
+ ! block_has_support( $block_type, array( 'spacing', 'padding' ), false ) ||
+ wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' )
+ ) {
+ unset( $attributes['style']['spacing']['padding'] );
}
- if ( $has_margin_support && ! $skip_margin ) {
- $spacing_block_styles['margin'] = $block_styles['spacing']['margin'] ?? null;
+ if (
+ ! block_has_support( $block_type, array( 'spacing', 'margin' ), false ) ||
+ wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' )
+ ) {
+ unset( $attributes['style']['spacing']['margin'] );
}
- return gutenberg_get_spacing_classes_and_styles( array( 'style' => array( 'spacing' => $spacing_block_styles ) ) );
+ return gutenberg_get_spacing_classes_and_styles( $attributes );
}
/**
diff --git a/phpunit/block-supports/spacing-test.php b/phpunit/block-supports/spacing-test.php
index 5c1ad9ee5c4ab3..ac789392e714ce 100644
--- a/phpunit/block-supports/spacing-test.php
+++ b/phpunit/block-supports/spacing-test.php
@@ -158,6 +158,63 @@ public function test_margin_with_individual_skipped_serialization_block_supports
$this->assertSame( $expected, $actual );
}
+ public function test_unsupported_padding_is_not_applied() {
+ $this->test_block_name = 'test/unsupported-padding-is-not-applied';
+ register_block_type(
+ $this->test_block_name,
+ array(
+ 'api_version' => 3,
+ 'attributes' => array(
+ 'style' => array(
+ 'type' => 'object',
+ ),
+ ),
+ 'supports' => array(
+ 'spacing' => array(
+ 'margin' => true,
+ ),
+ ),
+ )
+ );
+ $registry = WP_Block_Type_Registry::get_instance();
+ $block_type = $registry->get_registered( $this->test_block_name );
+ $block_atts = array(
+ 'style' => array(
+ 'spacing' => array(
+ 'margin' => '1px',
+ 'padding' => '2px',
+ ),
+ ),
+ );
+
+ $actual = gutenberg_apply_spacing_support( $block_type, $block_atts );
+ $expected = array(
+ 'style' => 'margin:1px;',
+ );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ public function test_spacing_without_style_attribute() {
+ $this->test_block_name = 'test/spacing-without-style-attribute';
+ register_block_type(
+ $this->test_block_name,
+ array(
+ 'api_version' => 3,
+ 'supports' => array(
+ 'spacing' => array(
+ 'margin' => true,
+ 'padding' => true,
+ ),
+ ),
+ )
+ );
+ $registry = WP_Block_Type_Registry::get_instance();
+ $block_type = $registry->get_registered( $this->test_block_name );
+
+ $this->assertSame( array(), gutenberg_apply_spacing_support( $block_type, array() ) );
+ }
+
/**
* @dataProvider data_get_spacing_classes_and_styles
*
From 1a1cf6ad9d31f84982e1f33aef848eb71be85899 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 8 Oct 2026 22:05:48 +0800
Subject: [PATCH 05/13] Use named support and skip variables, and filter the
attributes in place
---
lib/block-supports/spacing.php | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php
index d5c2c1d5c243ab..7534f395030810 100644
--- a/lib/block-supports/spacing.php
+++ b/lib/block-supports/spacing.php
@@ -43,29 +43,24 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
return array();
}
- if ( empty( $block_attributes['style'] ) ) {
+ if ( ! isset( $block_attributes['style']['spacing'] ) || ! is_array( $block_attributes['style']['spacing'] ) ) {
return array();
}
- $attributes = $block_attributes;
- if ( ! is_array( $attributes['style']['spacing'] ?? null ) ) {
- return array();
- }
+ $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
+ $has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false );
+ $skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
+ $skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
- if (
- ! block_has_support( $block_type, array( 'spacing', 'padding' ), false ) ||
- wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' )
- ) {
- unset( $attributes['style']['spacing']['padding'] );
+ if ( ! $has_padding_support || $skip_padding ) {
+ unset( $block_attributes['style']['spacing']['padding'] );
}
- if (
- ! block_has_support( $block_type, array( 'spacing', 'margin' ), false ) ||
- wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' )
- ) {
- unset( $attributes['style']['spacing']['margin'] );
+
+ if ( ! $has_margin_support || $skip_margin ) {
+ unset( $block_attributes['style']['spacing']['margin'] );
}
- return gutenberg_get_spacing_classes_and_styles( $attributes );
+ return gutenberg_get_spacing_classes_and_styles( $block_attributes );
}
/**
From 13a10902c1c2b1d2026038d94d75a4ab0018f317 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Tue, 13 Oct 2026 12:32:14 +0800
Subject: [PATCH 06/13] Expect trunk's minimum width and height in the Post
Navigation Link styles test
---
phpunit/blocks/render-block-post-navigation-link-test.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php
index 6a4686a3920ff3..d8a7ae9f30e741 100644
--- a/phpunit/blocks/render-block-post-navigation-link-test.php
+++ b/phpunit/blocks/render-block-post-navigation-link-test.php
@@ -135,7 +135,7 @@ public function test_border_shadow_and_spacing_styles() {
$this->assertTrue( $processor->next_tag( 'div' ) );
$this->assertSame( 'post-navigation-link-previous has-border-color has-accent-2-border-color wp-block-post-navigation-link', $processor->get_attribute( 'class' ) );
$this->assertSame(
- 'border-style:dashed;border-width:3px;box-shadow:10px 10px 5px #000000;padding-top:20px;margin-top:var(--wp--preset--spacing--30)',
+ 'border-style:dashed;border-width:3px;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:var(--wp--preset--spacing--30)',
$processor->get_attribute( 'style' )
);
}
From bed5aaf7b4f09d2b067c5de8fe5d64bddaaa7ae5 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Wed, 21 Oct 2026 20:17:02 +0800
Subject: [PATCH 07/13] Add the avatar style only when spacing gives one, and
trim the tests
Skip the wrapper style attribute when the spacing helper returns no styles, so an empty spacing object no longer prints style="". Drop the numeric spacing case, which tests style engine behaviour that differs from the editor, and trim the remaining tests to the cases that prove this change.
---
.../src/comment-author-avatar/index.php | 6 +-
phpunit/block-supports/spacing-test.php | 70 +------------------
...ender-block-comment-author-avatar-test.php | 13 +---
phpunit/blocks/render-block-icon-test.php | 17 ++---
...render-block-post-navigation-link-test.php | 21 ++----
5 files changed, 18 insertions(+), 109 deletions(-)
diff --git a/packages/block-library/src/comment-author-avatar/index.php b/packages/block-library/src/comment-author-avatar/index.php
index 297d5e273aeea5..50d75a54a09f3e 100644
--- a/packages/block-library/src/comment-author-avatar/index.php
+++ b/packages/block-library/src/comment-author-avatar/index.php
@@ -48,9 +48,9 @@ function render_block_core_comment_author_avatar( $attributes, $content, $block
);
// Spacing skips serialization, so it goes on the outer div, not the image.
- if ( isset( $attributes['style']['spacing'] ) ) {
- $spacing_styles = wp_get_spacing_classes_and_styles( $attributes );
- return sprintf( '%2$s
', esc_attr( $spacing_styles['style'] ?? '' ), $avatar_block );
+ $spacing_styles = wp_get_spacing_classes_and_styles( $attributes );
+ if ( ! empty( $spacing_styles['style'] ) ) {
+ return sprintf( '%2$s
', esc_attr( $spacing_styles['style'] ), $avatar_block );
}
return sprintf( '%s
', $avatar_block );
}
diff --git a/phpunit/block-supports/spacing-test.php b/phpunit/block-supports/spacing-test.php
index ac789392e714ce..c9220d41f46710 100644
--- a/phpunit/block-supports/spacing-test.php
+++ b/phpunit/block-supports/spacing-test.php
@@ -195,26 +195,6 @@ public function test_unsupported_padding_is_not_applied() {
$this->assertSame( $expected, $actual );
}
- public function test_spacing_without_style_attribute() {
- $this->test_block_name = 'test/spacing-without-style-attribute';
- register_block_type(
- $this->test_block_name,
- array(
- 'api_version' => 3,
- 'supports' => array(
- 'spacing' => array(
- 'margin' => true,
- 'padding' => true,
- ),
- ),
- )
- );
- $registry = WP_Block_Type_Registry::get_instance();
- $block_type = $registry->get_registered( $this->test_block_name );
-
- $this->assertSame( array(), gutenberg_apply_spacing_support( $block_type, array() ) );
- }
-
/**
* @dataProvider data_get_spacing_classes_and_styles
*
@@ -234,7 +214,7 @@ public function test_get_spacing_classes_and_styles( $block_attributes, $expecte
*/
public function data_get_spacing_classes_and_styles() {
return array(
- 'custom values' => array(
+ 'custom values' => array(
'block_attributes' => array(
'style' => array(
'spacing' => array(
@@ -250,7 +230,7 @@ public function data_get_spacing_classes_and_styles() {
'style' => 'padding-top:1px;padding-left:2em;margin:3px;',
),
),
- 'presets' => array(
+ 'presets' => array(
'block_attributes' => array(
'style' => array(
'spacing' => array(
@@ -263,45 +243,7 @@ public function data_get_spacing_classes_and_styles() {
'style' => 'padding:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--20);',
),
),
- 'block gap is ignored' => array(
- 'block_attributes' => array(
- 'style' => array(
- 'spacing' => array( 'blockGap' => '2em' ),
- ),
- ),
- 'expected' => array(),
- ),
- 'numeric values' => array(
- 'block_attributes' => array(
- 'style' => array(
- 'spacing' => array( 'padding' => array( 'top' => 10 ) ),
- ),
- ),
- 'expected' => array(),
- ),
- 'zero' => array(
- 'block_attributes' => array(
- 'style' => array(
- 'spacing' => array( 'margin' => '0' ),
- ),
- ),
- 'expected' => array(
- 'style' => 'margin:0;',
- ),
- ),
- 'empty spacing' => array(
- 'block_attributes' => array(
- 'style' => array(
- 'spacing' => array(),
- ),
- ),
- 'expected' => array(),
- ),
- 'no style' => array(
- 'block_attributes' => array(),
- 'expected' => array(),
- ),
- 'malformed spacing' => array(
+ 'malformed spacing' => array(
'block_attributes' => array(
'style' => array(
'spacing' => '10px',
@@ -309,12 +251,6 @@ public function data_get_spacing_classes_and_styles() {
),
'expected' => array(),
),
- 'malformed style' => array(
- 'block_attributes' => array(
- 'style' => 'padding:10px',
- ),
- 'expected' => array(),
- ),
);
}
}
diff --git a/phpunit/blocks/render-block-comment-author-avatar-test.php b/phpunit/blocks/render-block-comment-author-avatar-test.php
index 7330e7e853f633..2577b3a05d069d 100644
--- a/phpunit/blocks/render-block-comment-author-avatar-test.php
+++ b/phpunit/blocks/render-block-comment-author-avatar-test.php
@@ -66,29 +66,22 @@ public function test_wrapper_has_spacing_styles( $spacing, $expected_style ) {
*/
public function data_spacing_styles() {
return array(
- 'custom value' => array(
- 'spacing' => array( 'padding' => array( 'top' => '10px' ) ),
- 'expected_style' => 'padding-top:10px;',
- ),
- 'preset' => array(
+ 'preset' => array(
'spacing' => array( 'padding' => array( 'top' => 'var:preset|spacing|40' ) ),
'expected_style' => 'padding-top:var(--wp--preset--spacing--40);',
),
- 'padding and margin' => array(
+ 'padding and margin' => array(
'spacing' => array(
'margin' => array( 'top' => '5px' ),
'padding' => array( 'left' => '10px' ),
),
'expected_style' => 'padding-left:10px;margin-top:5px;',
),
- 'empty spacing array' => array(
- 'spacing' => array(),
- 'expected_style' => '',
- ),
);
}
public function test_wrapper_has_no_style_without_spacing() {
$this->assertNull( $this->get_wrapper_style( array() ) );
+ $this->assertNull( $this->get_wrapper_style( array( 'style' => array( 'spacing' => array() ) ) ) );
}
}
diff --git a/phpunit/blocks/render-block-icon-test.php b/phpunit/blocks/render-block-icon-test.php
index a24a9ebfb657eb..247fdb64970b21 100644
--- a/phpunit/blocks/render-block-icon-test.php
+++ b/phpunit/blocks/render-block-icon-test.php
@@ -108,19 +108,11 @@ public function test_shadow_keeps_the_style_engine_order() {
$this->assertSame( 'fill: none; color:#000;border-width:2px;box-shadow:var(--wp--preset--shadow--natural);width:48px;padding:4px;', $processor->get_attribute( 'style' ) );
}
- public function test_applies_color_border_width_and_padding_styles() {
+ public function test_applies_width_and_padding_styles() {
$output = gutenberg_render_block_core_icon(
array(
- 'icon' => 'core/caution',
- 'textColor' => 'accent',
- 'style' => array(
- 'color' => array( 'background' => '#ffeeee' ),
- 'border' => array(
- 'radius' => '4px',
- 'width' => '2px',
- 'style' => 'solid',
- 'color' => '#000000',
- ),
+ 'icon' => 'core/caution',
+ 'style' => array(
'dimensions' => array( 'width' => '48px' ),
'spacing' => array(
'padding' => array(
@@ -134,9 +126,8 @@ public function test_applies_color_border_width_and_padding_styles() {
$processor = new WP_HTML_Tag_Processor( $output );
$this->assertTrue( $processor->next_tag( 'svg' ) );
- $this->assertSame( 'has-text-color has-accent-color has-background has-border-color', $processor->get_attribute( 'class' ) );
$this->assertSame(
- 'fill: none; color:var(--wp--preset--color--accent);background-color:#ffeeee;border-color:#000000;border-radius:4px;border-style:solid;border-width:2px;width:48px;padding-top:var(--wp--preset--spacing--20);padding-left:8px;',
+ 'fill: none; width:48px;padding-top:var(--wp--preset--spacing--20);padding-left:8px;',
$processor->get_attribute( 'style' )
);
}
diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php
index d8a7ae9f30e741..8101a6f79d6fca 100644
--- a/phpunit/blocks/render-block-post-navigation-link-test.php
+++ b/phpunit/blocks/render-block-post-navigation-link-test.php
@@ -114,30 +114,19 @@ public function test_empty_wrapper_keeps_the_supports_that_serialize_as_usual()
}
public function test_rendered_link_includes_border_dimensions_shadow_and_spacing() {
- $output = $this->render_block( self::$second_post_id, $this->styled_attributes() );
-
- $this->assertStringContainsString( 'border-style:dashed', $output );
- $this->assertStringContainsString( 'border-width:3px', $output );
- $this->assertStringContainsString( 'min-height:100px', $output );
- $this->assertStringContainsString( 'min-width:200px', $output );
- $this->assertStringContainsString( 'box-shadow:10px 10px 5px #000000', $output );
- $this->assertStringContainsString( 'padding-top:20px', $output );
- $this->assertStringContainsString( 'margin-top:30px', $output );
- $this->assertStringContainsString( 'has-border-color', $output );
- $this->assertStringContainsString( 'has-accent-2-border-color', $output );
- }
-
- public function test_border_shadow_and_spacing_styles() {
$attributes = $this->styled_attributes();
$attributes['style']['spacing']['margin']['top'] = 'var:preset|spacing|30';
- $processor = new WP_HTML_Tag_Processor( $this->render_block( self::$second_post_id, $attributes ) );
+ $output = $this->render_block( self::$second_post_id, $attributes );
+
+ $processor = new WP_HTML_Tag_Processor( $output );
$this->assertTrue( $processor->next_tag( 'div' ) );
- $this->assertSame( 'post-navigation-link-previous has-border-color has-accent-2-border-color wp-block-post-navigation-link', $processor->get_attribute( 'class' ) );
$this->assertSame(
'border-style:dashed;border-width:3px;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:var(--wp--preset--spacing--30)',
$processor->get_attribute( 'style' )
);
+ $this->assertStringContainsString( 'has-border-color', $output );
+ $this->assertStringContainsString( 'has-accent-2-border-color', $output );
}
public function test_individual_border_sides_match_the_core_declaration_order() {
From 6cd336911ab7d583ea7551704b589cf395430aec Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Fri, 30 Oct 2026 17:17:39 +0800
Subject: [PATCH 08/13] Move the spacing helper to WordPress 7.3
---
backport-changelog/7.2/14094.md | 7 -------
lib/block-supports/spacing.php | 2 +-
2 files changed, 1 insertion(+), 8 deletions(-)
delete mode 100644 backport-changelog/7.2/14094.md
diff --git a/backport-changelog/7.2/14094.md b/backport-changelog/7.2/14094.md
deleted file mode 100644
index af2f1e32bd6b82..00000000000000
--- a/backport-changelog/7.2/14094.md
+++ /dev/null
@@ -1,7 +0,0 @@
-https://github.com/WordPress/wordpress-develop/pull/14094
-
-* https://github.com/WordPress/gutenberg/pull/84205
-* https://github.com/WordPress/gutenberg/pull/84206
-* https://github.com/WordPress/gutenberg/pull/84207
-* https://github.com/WordPress/gutenberg/pull/84208
-* https://github.com/WordPress/gutenberg/pull/84209
diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php
index 7534f395030810..ad6c445b109516 100644
--- a/lib/block-supports/spacing.php
+++ b/lib/block-supports/spacing.php
@@ -68,7 +68,7 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
* `getSpacingClassesAndStyles()`. Does not check block support or skipped
* serialization.
*
- * @since 7.2.0
+ * @since 7.3.0
*
* @param array $block_attributes Block attributes.
* @return array Array with `class` and `style` keys, each present only when non-empty.
From b2a7c2ec945f16e21933f45fbdf7b666dd41eeaa Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Mon, 2 Nov 2026 11:02:34 +0800
Subject: [PATCH 09/13] Return early when spacing helper attributes are not an
array
Matches the colour, border and background helpers, and orders the helper test docblock like theirs.
---
lib/block-supports/spacing.php | 4 ++++
phpunit/block-supports/spacing-test.php | 8 ++++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php
index ad6c445b109516..a72784ca5354ac 100644
--- a/lib/block-supports/spacing.php
+++ b/lib/block-supports/spacing.php
@@ -74,6 +74,10 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
* @return array Array with `class` and `style` keys, each present only when non-empty.
*/
function gutenberg_get_spacing_classes_and_styles( $block_attributes ) {
+ if ( ! is_array( $block_attributes ) ) {
+ return array();
+ }
+
$spacing = $block_attributes['style']['spacing'] ?? null;
if ( ! is_array( $spacing ) ) {
return array();
diff --git a/phpunit/block-supports/spacing-test.php b/phpunit/block-supports/spacing-test.php
index c9220d41f46710..3673943d69f6a0 100644
--- a/phpunit/block-supports/spacing-test.php
+++ b/phpunit/block-supports/spacing-test.php
@@ -196,10 +196,10 @@ public function test_unsupported_padding_is_not_applied() {
}
/**
- * @dataProvider data_get_spacing_classes_and_styles
- *
* @covers ::gutenberg_get_spacing_classes_and_styles
*
+ * @dataProvider data_get_spacing_classes_and_styles
+ *
* @param mixed $block_attributes Block attributes.
* @param array $expected Expected classes and styles.
*/
@@ -251,6 +251,10 @@ public function data_get_spacing_classes_and_styles() {
),
'expected' => array(),
),
+ 'object attributes' => array(
+ 'block_attributes' => (object) array( 'style' => array( 'spacing' => array( 'margin' => '3px' ) ) ),
+ 'expected' => array(),
+ ),
);
}
}
From d0264f34875748f6877769d7c436ee3277c2622c Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Mon, 2 Nov 2026 20:02:19 +0800
Subject: [PATCH 10/13] PHPStan: Baseline the spacing helper until Core has it
Also drops the Comment Author Avatar $spacing_string entry, which this PR fixes.
---
tools/phpstan/baseline.neon | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon
index a4d746827c5d0f..c136648fb0d504 100644
--- a/tools/phpstan/baseline.neon
+++ b/tools/phpstan/baseline.neon
@@ -103,8 +103,8 @@ parameters:
path: ../../packages/block-library/src/avatar/index.php
-
- message: '#^Variable \$spacing_string might not be defined\.$#'
- identifier: variable.undefined
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
count: 1
path: ../../packages/block-library/src/comment-author-avatar/index.php
@@ -126,6 +126,12 @@ parameters:
count: 1
path: ../../packages/block-library/src/gallery/index.php
+ -
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
+ count: 1
+ path: ../../packages/block-library/src/icon/index.php
+
-
message: '#^Parameter \#1 \$author_id of function get_author_posts_url expects int, string given\.$#'
identifier: argument.type
@@ -192,6 +198,12 @@ parameters:
count: 1
path: ../../packages/block-library/src/playlist/index.php
+ -
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
+ count: 1
+ path: ../../packages/block-library/src/post-navigation-link/index.php
+
-
message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#'
identifier: return.type
From 4dbff22b3a16f4f6143ad725f1197996ef84db54 Mon Sep 17 00:00:00 2001
From: Weston Ruter
Date: Wed, 4 Nov 2026 00:06:30 -0700
Subject: [PATCH 11/13] PHPStan: Generate the WordPress stubs from the core
backport
The block library calls wp_get_spacing_classes_and_styles(), which the
build prefixes to gutenberg_get_spacing_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 calls
were baselined as not found.
Generate the stubs from wordpress-develop PR 14094, which backports the
helper, and drop the three baselined errors. Regenerate them from trunk
once the backport is committed.
Co-Authored-By: Claude Opus 5.5 (medium effort)
Claude-Code-Session-Id: cfcf15e8-ccc1-4d78-a7c9-51f73e8e4b92
---
tools/phpstan/baseline.neon | 18 ------------------
tools/phpstan/wordpress-stubs/composer.json | 9 +++++----
2 files changed, 5 insertions(+), 22 deletions(-)
diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon
index c136648fb0d504..de4f2e3b8f1762 100644
--- a/tools/phpstan/baseline.neon
+++ b/tools/phpstan/baseline.neon
@@ -102,12 +102,6 @@ parameters:
count: 1
path: ../../packages/block-library/src/avatar/index.php
- -
- message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
- identifier: function.notFound
- count: 1
- path: ../../packages/block-library/src/comment-author-avatar/index.php
-
-
message: '#^Parameter \#1 \$from of function human_time_diff expects int, string given\.$#'
identifier: argument.type
@@ -126,12 +120,6 @@ parameters:
count: 1
path: ../../packages/block-library/src/gallery/index.php
- -
- message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
- identifier: function.notFound
- count: 1
- path: ../../packages/block-library/src/icon/index.php
-
-
message: '#^Parameter \#1 \$author_id of function get_author_posts_url expects int, string given\.$#'
identifier: argument.type
@@ -198,12 +186,6 @@ parameters:
count: 1
path: ../../packages/block-library/src/playlist/index.php
- -
- message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
- identifier: function.notFound
- count: 1
- path: ../../packages/block-library/src/post-navigation-link/index.php
-
-
message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#'
identifier: return.type
diff --git a/tools/phpstan/wordpress-stubs/composer.json b/tools/phpstan/wordpress-stubs/composer.json
index 9cec1ff9f257d7..bfebd1bb2301a5 100644
--- a/tools/phpstan/wordpress-stubs/composer.json
+++ b/tools/phpstan/wordpress-stubs/composer.json
@@ -1,12 +1,13 @@
{
"name": "php-stubs/wordpress-stubs",
- "version": "7.2.0-beta3.65220",
- "description": "WordPress stubs generated from https://github.com/WordPress/wordpress-develop/commit/140b182252392fb12733a9c7cc7d5136a522ba43 (r65220), in place of the released package.",
+ "version": "7.2.0-beta4.65250",
+ "description": "WordPress stubs generated from https://github.com/WordPress/wordpress-develop/pull/14094 at https://github.com/WordPress/wordpress-develop/commit/7272ad70d252109b37936ac3f5563f9b42c00b4b, based on r65250, in place of the released package.",
"license": "GPL-2.0-or-later",
"extra": {
"source": {
- "commit": "140b182252392fb12733a9c7cc7d5136a522ba43",
- "revision": 65220
+ "commit": "7272ad70d252109b37936ac3f5563f9b42c00b4b",
+ "pull-request": 14094,
+ "revision": 65250
}
}
}
From 2e315088343e83f239e9c762950684ec44389389 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:17:11 +0800
Subject: [PATCH 12/13] Revert the WordPress stubs pin to Core PR 14094
---
tools/phpstan/baseline.neon | 18 ++++++++++++++++++
tools/phpstan/wordpress-stubs/composer.json | 9 ++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon
index de4f2e3b8f1762..c136648fb0d504 100644
--- a/tools/phpstan/baseline.neon
+++ b/tools/phpstan/baseline.neon
@@ -102,6 +102,12 @@ parameters:
count: 1
path: ../../packages/block-library/src/avatar/index.php
+ -
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
+ count: 1
+ path: ../../packages/block-library/src/comment-author-avatar/index.php
+
-
message: '#^Parameter \#1 \$from of function human_time_diff expects int, string given\.$#'
identifier: argument.type
@@ -120,6 +126,12 @@ parameters:
count: 1
path: ../../packages/block-library/src/gallery/index.php
+ -
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
+ count: 1
+ path: ../../packages/block-library/src/icon/index.php
+
-
message: '#^Parameter \#1 \$author_id of function get_author_posts_url expects int, string given\.$#'
identifier: argument.type
@@ -186,6 +198,12 @@ parameters:
count: 1
path: ../../packages/block-library/src/playlist/index.php
+ -
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
+ count: 1
+ path: ../../packages/block-library/src/post-navigation-link/index.php
+
-
message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#'
identifier: return.type
diff --git a/tools/phpstan/wordpress-stubs/composer.json b/tools/phpstan/wordpress-stubs/composer.json
index bfebd1bb2301a5..9cec1ff9f257d7 100644
--- a/tools/phpstan/wordpress-stubs/composer.json
+++ b/tools/phpstan/wordpress-stubs/composer.json
@@ -1,13 +1,12 @@
{
"name": "php-stubs/wordpress-stubs",
- "version": "7.2.0-beta4.65250",
- "description": "WordPress stubs generated from https://github.com/WordPress/wordpress-develop/pull/14094 at https://github.com/WordPress/wordpress-develop/commit/7272ad70d252109b37936ac3f5563f9b42c00b4b, based on r65250, in place of the released package.",
+ "version": "7.2.0-beta3.65220",
+ "description": "WordPress stubs generated from https://github.com/WordPress/wordpress-develop/commit/140b182252392fb12733a9c7cc7d5136a522ba43 (r65220), in place of the released package.",
"license": "GPL-2.0-or-later",
"extra": {
"source": {
- "commit": "7272ad70d252109b37936ac3f5563f9b42c00b4b",
- "pull-request": 14094,
- "revision": 65250
+ "commit": "140b182252392fb12733a9c7cc7d5136a522ba43",
+ "revision": 65220
}
}
}
From 330dd227e485a4acc023d0cfd2e71f752a2abd0c Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:17:33 +0800
Subject: [PATCH 13/13] PHPStan: Ignore the missing
wp_get_spacing_classes_and_styles() function until the stubs include it
---
phpstan.neon.dist | 6 ++++++
tools/phpstan/baseline.neon | 18 ------------------
2 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index 7028e0f8142401..3e4ca5d42275b5 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -38,6 +38,12 @@ parameters:
message: '#^Function wp_get_shadow_classes_and_styles not found\.$#'
identifier: function.notFound
+ # wp_get_spacing_classes_and_styles() is new in WordPress Core: https://github.com/WordPress/wordpress-develop/pull/14094
+ # Remove this entry once the WordPress stubs are generated from a Core revision that includes it.
+ -
+ message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
+ identifier: function.notFound
+
# Level 3:
# WP_REST_Request implements ArrayAccess, and the WordPress stubs declare its offsetSet() with a method-level
# template (`@template TOffset of key-of`, `@param T[TOffset] $value`). PHPStan does not resolve that
diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon
index c136648fb0d504..de4f2e3b8f1762 100644
--- a/tools/phpstan/baseline.neon
+++ b/tools/phpstan/baseline.neon
@@ -102,12 +102,6 @@ parameters:
count: 1
path: ../../packages/block-library/src/avatar/index.php
- -
- message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
- identifier: function.notFound
- count: 1
- path: ../../packages/block-library/src/comment-author-avatar/index.php
-
-
message: '#^Parameter \#1 \$from of function human_time_diff expects int, string given\.$#'
identifier: argument.type
@@ -126,12 +120,6 @@ parameters:
count: 1
path: ../../packages/block-library/src/gallery/index.php
- -
- message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
- identifier: function.notFound
- count: 1
- path: ../../packages/block-library/src/icon/index.php
-
-
message: '#^Parameter \#1 \$author_id of function get_author_posts_url expects int, string given\.$#'
identifier: argument.type
@@ -198,12 +186,6 @@ parameters:
count: 1
path: ../../packages/block-library/src/playlist/index.php
- -
- message: '#^Function wp_get_spacing_classes_and_styles not found\.$#'
- identifier: function.notFound
- count: 1
- path: ../../packages/block-library/src/post-navigation-link/index.php
-
-
message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#'
identifier: return.type