From cc99845d911f57804ba989601d60062c7da02e5a Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 08:15:11 +0800 Subject: [PATCH 01/12] Shadow: Add a PHP helper for block support classes and styles --- lib/block-supports/shadow.php | 27 ++++- packages/block-library/package.json | 3 +- packages/block-library/src/avatar/index.php | 4 +- .../src/navigation-submenu/index.php | 8 +- .../src/post-featured-image/index.php | 9 +- .../src/post-navigation-link/index.php | 21 +++- phpunit/block-supports/shadow-test.php | 60 +++++++++++ phpunit/blocks/render-block-avatar-test.php | 80 ++++++++++++++ .../render-block-navigation-submenu-test.php | 34 ++++++ .../render-block-post-featured-image-test.php | 101 ++++++++++++++++++ ...render-block-post-navigation-link-test.php | 16 +++ 11 files changed, 341 insertions(+), 22 deletions(-) create mode 100644 phpunit/blocks/render-block-avatar-test.php create mode 100644 phpunit/blocks/render-block-post-featured-image-test.php diff --git a/lib/block-supports/shadow.php b/lib/block-supports/shadow.php index 3a6b2ebee3de0a..7d8f6e5a9651db 100644 --- a/lib/block-supports/shadow.php +++ b/lib/block-supports/shadow.php @@ -54,13 +54,32 @@ function gutenberg_apply_shadow_support( $block_type, $block_attributes ) { return array(); } - $shadow_block_styles = array(); + return gutenberg_get_shadow_classes_and_styles( $block_attributes ); +} - $custom_shadow = $block_attributes['style']['shadow'] ?? null; - $shadow_block_styles['shadow'] = $custom_shadow; +/** + * Generates shadow CSS classes and inline styles from block attributes. + * + * The PHP counterpart of the JS `getShadowClassesAndStyles()`. Support and + * serialization checks are left to the caller. + * + * @since 7.2.0 + * + * @param array $block_attributes Block attributes. + * @return array Shadow CSS classes and inline styles, each key present only when non-empty. + */ +function gutenberg_get_shadow_classes_and_styles( $block_attributes ) { + $shadow = null; + if ( isset( $block_attributes['style'] ) && is_array( $block_attributes['style'] ) ) { + $shadow = $block_attributes['style']['shadow'] ?? null; + } $attributes = array(); - $styles = gutenberg_style_engine_get_styles( $shadow_block_styles ); + $styles = gutenberg_style_engine_get_styles( array( 'shadow' => $shadow ) ); + + 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 e6f461b3dcbcf0..3981ea06a57c95 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -73,7 +73,8 @@ "wp_get_typography_font_size_value", "wp_style_engine_get_styles", "wp_get_global_styles", - "wp_get_global_settings" + "wp_get_global_settings", + "wp_get_shadow_classes_and_styles" ], "suffixClasses": [ "WP_Navigation_Block_Renderer" diff --git a/packages/block-library/src/avatar/index.php b/packages/block-library/src/avatar/index.php index c2571754326851..0f56ce461a08f6 100644 --- a/packages/block-library/src/avatar/index.php +++ b/packages/block-library/src/avatar/index.php @@ -19,7 +19,7 @@ function render_block_core_avatar( $attributes, $content, $block ) { $size = $attributes['size'] ?? 96; $wrapper_attributes = get_block_wrapper_attributes(); $border_attributes = get_block_core_avatar_border_attributes( $attributes ); - $shadow_styles = wp_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ?? null ) ); + $shadow_attributes = wp_get_shadow_classes_and_styles( $attributes ); // Class gets passed through `esc_attr` via `get_avatar`. $image_classes = ! empty( $border_attributes['class'] ) @@ -29,7 +29,7 @@ function render_block_core_avatar( $attributes, $content, $block ) { // Unlike class, `get_avatar` doesn't filter the styles via `esc_attr`. // The style engine does pass the border and shadow styles through // `safecss_filter_attr` however. - $image_css = ( $border_attributes['style'] ?? '' ) . ( $shadow_styles['css'] ?? '' ); + $image_css = ( $border_attributes['style'] ?? '' ) . ( $shadow_attributes['style'] ?? '' ); $image_styles = ! empty( $image_css ) ? sprintf( ' style="%s"', esc_attr( $image_css ) ) : ''; diff --git a/packages/block-library/src/navigation-submenu/index.php b/packages/block-library/src/navigation-submenu/index.php index 687a6d8e7545b1..3ca728cc83d251 100644 --- a/packages/block-library/src/navigation-submenu/index.php +++ b/packages/block-library/src/navigation-submenu/index.php @@ -277,11 +277,9 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) { * Shadow serialization is skipped for this block so the shadow lands on the * dropdown panel, the floating layer it is meant for, and not the menu item. */ - if ( ! empty( $attributes['style']['shadow'] ) ) { - $shadow_styles = wp_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ) ); - if ( ! empty( $shadow_styles['css'] ) ) { - $style_attribute .= $shadow_styles['css']; - } + $shadow_attributes = wp_get_shadow_classes_and_styles( $attributes ); + if ( ! empty( $shadow_attributes['style'] ) ) { + $style_attribute .= $shadow_attributes['style']; } if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) { diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php index 593003f10e1c51..08ac73adff0705 100644 --- a/packages/block-library/src/post-featured-image/index.php +++ b/packages/block-library/src/post-featured-image/index.php @@ -64,12 +64,9 @@ function render_block_core_post_featured_image( $attributes, $content, $block ) if ( ! empty( $attributes['scale'] ) ) { $extra_styles .= esc_attr( safecss_filter_attr( 'object-fit:' . $attributes['scale'] ) ) . ';'; } - if ( ! empty( $attributes['style']['shadow'] ) ) { - $shadow_styles = wp_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ) ); - - if ( ! empty( $shadow_styles['css'] ) ) { - $extra_styles .= $shadow_styles['css']; - } + $shadow_attributes = wp_get_shadow_classes_and_styles( $attributes ); + if ( ! empty( $shadow_attributes['style'] ) ) { + $extra_styles .= $shadow_attributes['style']; } if ( ! empty( $extra_styles ) ) { diff --git a/packages/block-library/src/post-navigation-link/index.php b/packages/block-library/src/post-navigation-link/index.php index 047b05d42d756d..c42692e5d4abb1 100644 --- a/packages/block-library/src/post-navigation-link/index.php +++ b/packages/block-library/src/post-navigation-link/index.php @@ -215,15 +215,19 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { } } - $styles = wp_style_engine_get_styles( + $background_and_border_output = wp_style_engine_get_styles( array( 'background' => $background_styles, 'border' => $border_styles, + ) + ); + $shadow_output = wp_get_shadow_classes_and_styles( $attributes ); + $dimensions_and_spacing_output = wp_style_engine_get_styles( + array( 'dimensions' => array( 'minHeight' => $block_styles['dimensions']['minHeight'] ?? null, '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, @@ -231,7 +235,16 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { ) ); - $class_names = $styles['classnames'] ?? ''; + $class_names = implode( + ' ', + array_filter( + array( + $background_and_border_output['classnames'] ?? '', + $shadow_output['class'] ?? '', + $dimensions_and_spacing_output['classnames'] ?? '', + ) + ) + ); // The style engine only adds `has-background` for a gradient, the background block support adds it for an image too. if ( ! empty( $background_styles['backgroundImage'] ) && ! in_array( 'has-background', explode( ' ', $class_names ), true ) ) { @@ -240,7 +253,7 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { return array( 'class' => $class_names, - 'style' => $styles['css'] ?? '', + 'style' => ( $background_and_border_output['css'] ?? '' ) . ( $shadow_output['style'] ?? '' ) . ( $dimensions_and_spacing_output['css'] ?? '' ), ); } diff --git a/phpunit/block-supports/shadow-test.php b/phpunit/block-supports/shadow-test.php index edcd1ff62061e5..d490a938873f7e 100644 --- a/phpunit/block-supports/shadow-test.php +++ b/phpunit/block-supports/shadow-test.php @@ -108,4 +108,64 @@ public function data_generate_shadow_fixtures() { ), ); } + + /** + * Tests that shadow classes and styles are generated from block attributes. + * + * @covers ::gutenberg_get_shadow_classes_and_styles + * + * @dataProvider data_get_shadow_classes_and_styles + * + * @param mixed $block_attributes Block attributes. + * @param array $expected Expected shadow classes and styles. + */ + public function test_gutenberg_get_shadow_classes_and_styles( $block_attributes, $expected ) { + $this->assertSame( $expected, gutenberg_get_shadow_classes_and_styles( $block_attributes ) ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_get_shadow_classes_and_styles() { + return array( + 'custom shadow' => array( + 'block_attributes' => array( 'style' => array( 'shadow' => '1px 1px 1px #000' ) ), + 'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000;' ), + ), + 'preset shadow' => array( + 'block_attributes' => array( 'style' => array( 'shadow' => 'var:preset|shadow|natural' ) ), + 'expected' => array( 'style' => 'box-shadow:var(--wp--preset--shadow--natural);' ), + ), + 'numeric shadow' => array( + 'block_attributes' => array( 'style' => array( 'shadow' => 5 ) ), + 'expected' => array(), + ), + 'zero shadow' => array( + 'block_attributes' => array( 'style' => array( 'shadow' => 0 ) ), + 'expected' => array(), + ), + 'empty shadow' => array( + 'block_attributes' => array( 'style' => array( 'shadow' => '' ) ), + 'expected' => array(), + ), + 'no style attribute' => array( + 'block_attributes' => array(), + 'expected' => array(), + ), + 'non-array style' => array( + 'block_attributes' => array( 'style' => 'box-shadow:1px 1px 1px #000' ), + 'expected' => array(), + ), + 'non-array shadow value' => array( + 'block_attributes' => array( 'style' => array( 'shadow' => array( '1px 1px 1px #000' ) ) ), + 'expected' => array(), + ), + 'non-array attributes' => array( + 'block_attributes' => null, + 'expected' => array(), + ), + ); + } } diff --git a/phpunit/blocks/render-block-avatar-test.php b/phpunit/blocks/render-block-avatar-test.php new file mode 100644 index 00000000000000..2639fde51c0bfc --- /dev/null +++ b/phpunit/blocks/render-block-avatar-test.php @@ -0,0 +1,80 @@ +user->create( array( 'display_name' => 'Avatar Author' ) ); + } + + /** + * Renders an Avatar block and returns the image's class and style attributes. + * + * @param array $style Style attribute. + * @return array Class and style of the image. + */ + private function render_image_attributes( $style ) { + $block = new WP_Block( + array( + 'blockName' => 'core/avatar', + 'attrs' => array( + 'userId' => self::$user_id, + 'style' => $style, + ), + ) + ); + + $processor = new WP_HTML_Tag_Processor( $block->render() ); + $processor->next_tag( 'img' ); + + return array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $processor->get_attribute( 'style' ), + ); + } + + public function test_shadow_is_applied_to_the_image() { + $actual = $this->render_image_attributes( array( 'shadow' => 'var:preset|shadow|natural' ) ); + + $this->assertSame( 'avatar avatar-96 photo wp-block-avatar__image', $actual['class'] ); + $this->assertSame( 'box-shadow:var(--wp--preset--shadow--natural);', $actual['style'] ); + } + + public function test_shadow_follows_border_on_the_image() { + $actual = $this->render_image_attributes( + array( + 'border' => array( + 'radius' => '10px', + 'color' => '#ff0000', + ), + 'shadow' => '1px 1px 1px #000', + ) + ); + + $this->assertSame( 'avatar avatar-96 photo wp-block-avatar__image has-border-color', $actual['class'] ); + $this->assertSame( 'border-color:#ff0000;border-radius:10px;box-shadow:1px 1px 1px #000;', $actual['style'] ); + } + + public function test_no_shadow_leaves_no_style() { + $actual = $this->render_image_attributes( array() ); + + $this->assertNull( $actual['style'] ); + } +} diff --git a/phpunit/blocks/render-block-navigation-submenu-test.php b/phpunit/blocks/render-block-navigation-submenu-test.php index c0e3352ecc82c6..d9ad99263f79db 100644 --- a/phpunit/blocks/render-block-navigation-submenu-test.php +++ b/phpunit/blocks/render-block-navigation-submenu-test.php @@ -276,4 +276,38 @@ public function test_should_apply_open_on_click_for_legacy_openSubmenusOnClick_a 'Submenu should not have "open-on-hover-click" class when legacy openSubmenusOnClick was true' ); } + + /** + * @covers ::gutenberg_render_block_core_navigation_submenu + */ + public function test_should_apply_shadow_to_the_submenu_container() { + $page_id = self::$page->ID; + + $parsed_blocks = parse_blocks( + ' + + ' + ); + + $navigation_submenu_block = new WP_Block( $parsed_blocks[0], array( 'overlayTextColor' => 'purple' ) ); + + $tags = new WP_HTML_Tag_Processor( + gutenberg_render_block_core_navigation_submenu( + $navigation_submenu_block->attributes, + array(), + $navigation_submenu_block + ) + ); + $tags->next_tag( 'li' ); + $this->assertNull( $tags->get_attribute( 'style' ), 'Shadow should not be applied to the menu item.' ); + + $tags->next_tag( + array( + 'tag_name' => 'ul', + 'class_name' => 'wp-block-navigation__submenu-container', + ) + ); + $this->assertSame( 'wp-block-navigation__submenu-container has-text-color has-purple-color', $tags->get_attribute( 'class' ) ); + $this->assertSame( 'box-shadow:var(--wp--preset--shadow--natural)', $tags->get_attribute( 'style' ) ); + } } diff --git a/phpunit/blocks/render-block-post-featured-image-test.php b/phpunit/blocks/render-block-post-featured-image-test.php new file mode 100644 index 00000000000000..ec4630c43bb9b2 --- /dev/null +++ b/phpunit/blocks/render-block-post-featured-image-test.php @@ -0,0 +1,101 @@ +post->create(); + self::$attachment_id = $factory->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg', self::$post_id ); + set_post_thumbnail( self::$post_id, self::$attachment_id ); + } + + public static function wpTearDownAfterClass() { + wp_delete_post( self::$attachment_id, true ); + } + + /** + * Renders a Post Featured Image block and returns the class and style + * attributes of the image and the overlay. + * + * @param array $attributes Block attributes. + * @return array Class and style of the image and the overlay. + */ + private function render_attributes( $attributes ) { + $block = new WP_Block( + array( + 'blockName' => 'core/post-featured-image', + 'attrs' => $attributes, + ), + array( 'postId' => self::$post_id ) + ); + + $processor = new WP_HTML_Tag_Processor( $block->render() ); + $processor->next_tag( 'img' ); + $actual = array( + 'image_class' => $processor->get_attribute( 'class' ), + 'image_style' => $processor->get_attribute( 'style' ), + ); + if ( $processor->next_tag( 'span' ) ) { + $actual['overlay_class'] = $processor->get_attribute( 'class' ); + $actual['overlay_style'] = $processor->get_attribute( 'style' ); + } + + return $actual; + } + + public function test_shadow_is_applied_to_the_image() { + $actual = $this->render_attributes( + array( 'style' => array( 'shadow' => 'var:preset|shadow|natural' ) ) + ); + + $this->assertSame( 'object-fit:cover;box-shadow:var(--wp--preset--shadow--natural);', $actual['image_style'] ); + } + + public function test_shadow_follows_border_and_dimensions_on_the_image() { + $actual = $this->render_attributes( + array( + 'dimRatio' => 50, + 'style' => array( + 'border' => array( + 'radius' => '10px', + 'color' => '#ff0000', + ), + 'shadow' => '1px 1px 1px #000', + ), + ) + ); + + $this->assertSame( 'has-border-color wp-post-image', $actual['image_class'] ); + $this->assertSame( 'border-color:#ff0000;border-radius:10px;object-fit:cover;box-shadow:1px 1px 1px #000;', $actual['image_style'] ); + $this->assertSame( 'wp-block-post-featured-image__overlay has-border-color has-background-dim has-background-dim-50', $actual['overlay_class'] ); + $this->assertSame( 'border-color:#ff0000;border-radius:10px', $actual['overlay_style'] ); + } + + public function test_no_shadow_leaves_no_style() { + $actual = $this->render_attributes( array( 'style' => array( 'shadow' => '' ) ) ); + + $this->assertSame( 'object-fit:cover;', $actual['image_style'] ); + } +} diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php index 76071e23857678..9dc3e7cf1585b5 100644 --- a/phpunit/blocks/render-block-post-navigation-link-test.php +++ b/phpunit/blocks/render-block-post-navigation-link-test.php @@ -227,4 +227,20 @@ public function test_null_from_the_post_link_filter_omits_the_styles() { $this->assertStringNotContainsString( 'style=', $output ); $this->assertStringNotContainsString( 'has-border-color', $output ); } + + public function test_rendered_link_full_support_classes_and_styles() { + $output = $this->render_block( self::$second_post_id, $this->styled_attributes() ); + + $processor = new WP_HTML_Tag_Processor( $output ); + $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:30px', + $processor->get_attribute( 'style' ) + ); + } } From d03718c75067247bf1c29bff3123eaa02230fbce Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:14:49 +0800 Subject: [PATCH 02/12] Address review feedback --- lib/block-supports/shadow.php | 14 ++++------- packages/block-library/package.json | 4 ++-- phpunit/block-supports/shadow-test.php | 24 +++++++++---------- phpunit/blocks/render-block-avatar-test.php | 9 +------ .../render-block-navigation-submenu-test.php | 14 +++++------ .../render-block-post-featured-image-test.php | 4 ++-- 6 files changed, 28 insertions(+), 41 deletions(-) diff --git a/lib/block-supports/shadow.php b/lib/block-supports/shadow.php index 7d8f6e5a9651db..17bfc89d199cd0 100644 --- a/lib/block-supports/shadow.php +++ b/lib/block-supports/shadow.php @@ -58,21 +58,17 @@ function gutenberg_apply_shadow_support( $block_type, $block_attributes ) { } /** - * Generates shadow CSS classes and inline styles from block attributes. - * - * The PHP counterpart of the JS `getShadowClassesAndStyles()`. Support and - * serialization checks are left to the caller. + * Returns shadow classes and inline styles for block attributes, like the JS + * `getShadowClassesAndStyles()`. Does not check block support or skipped + * serialization. * * @since 7.2.0 * * @param array $block_attributes Block attributes. - * @return array Shadow CSS classes and inline styles, each key present only when non-empty. + * @return array Array with `class` and `style` keys, each present only when non-empty. */ function gutenberg_get_shadow_classes_and_styles( $block_attributes ) { - $shadow = null; - if ( isset( $block_attributes['style'] ) && is_array( $block_attributes['style'] ) ) { - $shadow = $block_attributes['style']['shadow'] ?? null; - } + $shadow = $block_attributes['style']['shadow'] ?? null; $attributes = array(); $styles = gutenberg_style_engine_get_styles( array( 'shadow' => $shadow ) ); diff --git a/packages/block-library/package.json b/packages/block-library/package.json index 3981ea06a57c95..292f1cebc69789 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -71,10 +71,10 @@ "wp_apply_colors_support", "wp_enqueue_block_support_styles", "wp_get_typography_font_size_value", + "wp_get_shadow_classes_and_styles", "wp_style_engine_get_styles", "wp_get_global_styles", - "wp_get_global_settings", - "wp_get_shadow_classes_and_styles" + "wp_get_global_settings" ], "suffixClasses": [ "WP_Navigation_Block_Renderer" diff --git a/phpunit/block-supports/shadow-test.php b/phpunit/block-supports/shadow-test.php index d490a938873f7e..9fb1c661a703b0 100644 --- a/phpunit/block-supports/shadow-test.php +++ b/phpunit/block-supports/shadow-test.php @@ -18,7 +18,9 @@ public function set_up() { } public function tear_down() { - unregister_block_type( $this->test_block_name ); + if ( $this->test_block_name ) { + unregister_block_type( $this->test_block_name ); + } $this->test_block_name = null; parent::tear_down(); } @@ -110,8 +112,6 @@ public function data_generate_shadow_fixtures() { } /** - * Tests that shadow classes and styles are generated from block attributes. - * * @covers ::gutenberg_get_shadow_classes_and_styles * * @dataProvider data_get_shadow_classes_and_styles @@ -130,39 +130,39 @@ public function test_gutenberg_get_shadow_classes_and_styles( $block_attributes, */ public function data_get_shadow_classes_and_styles() { return array( - 'custom shadow' => array( + 'custom shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => '1px 1px 1px #000' ) ), 'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000;' ), ), - 'preset shadow' => array( + 'preset shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => 'var:preset|shadow|natural' ) ), 'expected' => array( 'style' => 'box-shadow:var(--wp--preset--shadow--natural);' ), ), - 'numeric shadow' => array( + 'numeric shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => 5 ) ), 'expected' => array(), ), - 'zero shadow' => array( + 'zero shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => 0 ) ), 'expected' => array(), ), - 'empty shadow' => array( + 'empty shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => '' ) ), 'expected' => array(), ), - 'no style attribute' => array( + 'no style attribute' => array( 'block_attributes' => array(), 'expected' => array(), ), - 'non-array style' => array( + 'non-array style' => array( 'block_attributes' => array( 'style' => 'box-shadow:1px 1px 1px #000' ), 'expected' => array(), ), - 'non-array shadow value' => array( + 'array shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => array( '1px 1px 1px #000' ) ) ), 'expected' => array(), ), - 'non-array attributes' => array( + 'non-array attributes' => array( 'block_attributes' => null, 'expected' => array(), ), diff --git a/phpunit/blocks/render-block-avatar-test.php b/phpunit/blocks/render-block-avatar-test.php index 2639fde51c0bfc..2b16e72ec11df4 100644 --- a/phpunit/blocks/render-block-avatar-test.php +++ b/phpunit/blocks/render-block-avatar-test.php @@ -42,7 +42,7 @@ private function render_image_attributes( $style ) { ); $processor = new WP_HTML_Tag_Processor( $block->render() ); - $processor->next_tag( 'img' ); + $this->assertTrue( $processor->next_tag( 'img' ) ); return array( 'class' => $processor->get_attribute( 'class' ), @@ -53,7 +53,6 @@ private function render_image_attributes( $style ) { public function test_shadow_is_applied_to_the_image() { $actual = $this->render_image_attributes( array( 'shadow' => 'var:preset|shadow|natural' ) ); - $this->assertSame( 'avatar avatar-96 photo wp-block-avatar__image', $actual['class'] ); $this->assertSame( 'box-shadow:var(--wp--preset--shadow--natural);', $actual['style'] ); } @@ -71,10 +70,4 @@ public function test_shadow_follows_border_on_the_image() { $this->assertSame( 'avatar avatar-96 photo wp-block-avatar__image has-border-color', $actual['class'] ); $this->assertSame( 'border-color:#ff0000;border-radius:10px;box-shadow:1px 1px 1px #000;', $actual['style'] ); } - - public function test_no_shadow_leaves_no_style() { - $actual = $this->render_image_attributes( array() ); - - $this->assertNull( $actual['style'] ); - } } diff --git a/phpunit/blocks/render-block-navigation-submenu-test.php b/phpunit/blocks/render-block-navigation-submenu-test.php index d9ad99263f79db..12c2f5663cb37c 100644 --- a/phpunit/blocks/render-block-navigation-submenu-test.php +++ b/phpunit/blocks/render-block-navigation-submenu-test.php @@ -298,16 +298,14 @@ public function test_should_apply_shadow_to_the_submenu_container() { $navigation_submenu_block ) ); - $tags->next_tag( 'li' ); - $this->assertNull( $tags->get_attribute( 'style' ), 'Shadow should not be applied to the menu item.' ); - - $tags->next_tag( - array( - 'tag_name' => 'ul', - 'class_name' => 'wp-block-navigation__submenu-container', + $this->assertTrue( + $tags->next_tag( + array( + 'tag_name' => 'ul', + 'class_name' => 'wp-block-navigation__submenu-container', + ) ) ); - $this->assertSame( 'wp-block-navigation__submenu-container has-text-color has-purple-color', $tags->get_attribute( 'class' ) ); $this->assertSame( 'box-shadow:var(--wp--preset--shadow--natural)', $tags->get_attribute( 'style' ) ); } } diff --git a/phpunit/blocks/render-block-post-featured-image-test.php b/phpunit/blocks/render-block-post-featured-image-test.php index ec4630c43bb9b2..ac6a17c1d977ec 100644 --- a/phpunit/blocks/render-block-post-featured-image-test.php +++ b/phpunit/blocks/render-block-post-featured-image-test.php @@ -52,7 +52,7 @@ private function render_attributes( $attributes ) { ); $processor = new WP_HTML_Tag_Processor( $block->render() ); - $processor->next_tag( 'img' ); + $this->assertTrue( $processor->next_tag( 'img' ) ); $actual = array( 'image_class' => $processor->get_attribute( 'class' ), 'image_style' => $processor->get_attribute( 'style' ), @@ -93,7 +93,7 @@ public function test_shadow_follows_border_and_dimensions_on_the_image() { $this->assertSame( 'border-color:#ff0000;border-radius:10px', $actual['overlay_style'] ); } - public function test_no_shadow_leaves_no_style() { + public function test_empty_shadow_is_ignored() { $actual = $this->render_attributes( array( 'style' => array( 'shadow' => '' ) ) ); $this->assertSame( 'object-fit:cover;', $actual['image_style'] ); From 78784f174cd20be74f5192edbbda6a47e5cb7959 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/12] 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 f1e43d12454dce8050ebb516c6959dbf233ba940 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:28:07 +0800 Subject: [PATCH 04/12] 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 9dc3e7cf1585b5..3acba75ea1c37e 100644 --- a/phpunit/blocks/render-block-post-navigation-link-test.php +++ b/phpunit/blocks/render-block-post-navigation-link-test.php @@ -239,7 +239,7 @@ public function test_rendered_link_full_support_classes_and_styles() { $processor->get_attribute( 'class' ) ); $this->assertSame( - 'border-style:dashed;border-width:3px;box-shadow:10px 10px 5px #000000;padding-top:20px;margin-top:30px', + 'border-style:dashed;border-width:3px;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:30px', $processor->get_attribute( 'style' ) ); } From 59bbed057ccf6d3668384b9aeda2afe4ae3e6342 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:18:40 +0800 Subject: [PATCH 05/12] Migrate Search and Icon to the shadow helper and trim the tests Search and Icon now get their shadow from the helper, like the other blocks in this PR, with the same output as trunk. Each gets one render test. The tests now cover the helper's own cases and one migration per block. Cases that re-tested the style engine are dropped. --- packages/block-library/src/icon/index.php | 26 ++++++--- packages/block-library/src/search/index.php | 17 +++--- phpunit/block-supports/shadow-test.php | 16 ------ phpunit/blocks/render-block-avatar-test.php | 6 --- phpunit/blocks/render-block-icon-test.php | 20 +++++++ .../render-block-post-featured-image-test.php | 45 ++++------------ phpunit/blocks/render-block-search-test.php | 54 +++++++++++++++++++ 7 files changed, 112 insertions(+), 72 deletions(-) create mode 100644 phpunit/blocks/render-block-search-test.php diff --git a/packages/block-library/src/icon/index.php b/packages/block-library/src/icon/index.php index fe1734b7e30f5f..7543283d1774ac 100644 --- a/packages/block-library/src/icon/index.php +++ b/packages/block-library/src/icon/index.php @@ -83,9 +83,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'] ) ) { @@ -101,15 +98,32 @@ function render_block_core_icon( $attributes ) { } // Generate styles and classes. - $styles = wp_style_engine_get_styles( + $color_and_border_output = wp_style_engine_get_styles( array( 'color' => $color_styles, 'background' => $background_styles, 'border' => $border_styles, - 'shadow' => $shadow_styles, - 'spacing' => $spacing_styles, + ) + ); + $shadow_output = wp_get_shadow_classes_and_styles( $attributes ); + $dimensions_and_spacing_output = wp_style_engine_get_styles( + array( 'dimensions' => $dimensions_styles, + 'spacing' => $spacing_styles, + ) + ); + $styles = array( + 'classnames' => implode( + ' ', + array_filter( + array( + $color_and_border_output['classnames'] ?? '', + $shadow_output['class'] ?? '', + $dimensions_and_spacing_output['classnames'] ?? '', + ) + ) ), + 'css' => ( $color_and_border_output['css'] ?? '' ) . ( $shadow_output['style'] ?? '' ) . ( $dimensions_and_spacing_output['css'] ?? '' ), ); $svg = wp_get_icon( diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 29850a5cc2a550..00c912706e5d0a 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -472,16 +472,13 @@ function styles_for_block_core_search( $attributes ) { } // Shadow lands on the same elements as the border. - if ( ! empty( $attributes['style']['shadow'] ) && is_string( $attributes['style']['shadow'] ) ) { - $shadow_styles = wp_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ) ); - - if ( ! empty( $shadow_styles['css'] ) ) { - if ( $is_button_inside ) { - $wrapper_styles[] = $shadow_styles['css']; - } else { - $button_styles[] = $shadow_styles['css']; - $input_styles[] = $shadow_styles['css']; - } + $shadow_attributes = wp_get_shadow_classes_and_styles( $attributes ); + if ( ! empty( $shadow_attributes['style'] ) ) { + if ( $is_button_inside ) { + $wrapper_styles[] = $shadow_attributes['style']; + } else { + $button_styles[] = $shadow_attributes['style']; + $input_styles[] = $shadow_attributes['style']; } } diff --git a/phpunit/block-supports/shadow-test.php b/phpunit/block-supports/shadow-test.php index 9fb1c661a703b0..0b32cd392dd003 100644 --- a/phpunit/block-supports/shadow-test.php +++ b/phpunit/block-supports/shadow-test.php @@ -138,30 +138,14 @@ public function data_get_shadow_classes_and_styles() { 'block_attributes' => array( 'style' => array( 'shadow' => 'var:preset|shadow|natural' ) ), 'expected' => array( 'style' => 'box-shadow:var(--wp--preset--shadow--natural);' ), ), - 'numeric shadow' => array( - 'block_attributes' => array( 'style' => array( 'shadow' => 5 ) ), - 'expected' => array(), - ), - 'zero shadow' => array( - 'block_attributes' => array( 'style' => array( 'shadow' => 0 ) ), - 'expected' => array(), - ), 'empty shadow' => array( 'block_attributes' => array( 'style' => array( 'shadow' => '' ) ), 'expected' => array(), ), - 'no style attribute' => array( - 'block_attributes' => array(), - 'expected' => array(), - ), 'non-array style' => array( 'block_attributes' => array( 'style' => 'box-shadow:1px 1px 1px #000' ), 'expected' => array(), ), - 'array shadow' => array( - 'block_attributes' => array( 'style' => array( 'shadow' => array( '1px 1px 1px #000' ) ) ), - 'expected' => array(), - ), 'non-array attributes' => array( 'block_attributes' => null, 'expected' => array(), diff --git a/phpunit/blocks/render-block-avatar-test.php b/phpunit/blocks/render-block-avatar-test.php index 2b16e72ec11df4..02bf59ae98a297 100644 --- a/phpunit/blocks/render-block-avatar-test.php +++ b/phpunit/blocks/render-block-avatar-test.php @@ -50,12 +50,6 @@ private function render_image_attributes( $style ) { ); } - public function test_shadow_is_applied_to_the_image() { - $actual = $this->render_image_attributes( array( 'shadow' => 'var:preset|shadow|natural' ) ); - - $this->assertSame( 'box-shadow:var(--wp--preset--shadow--natural);', $actual['style'] ); - } - public function test_shadow_follows_border_on_the_image() { $actual = $this->render_image_attributes( array( diff --git a/phpunit/blocks/render-block-icon-test.php b/phpunit/blocks/render-block-icon-test.php index fc382221767621..c24f7605911683 100644 --- a/phpunit/blocks/render-block-icon-test.php +++ b/phpunit/blocks/render-block-icon-test.php @@ -88,6 +88,26 @@ public function test_preserves_intrinsic_svg_style_when_applying_rotation() { $this->assertLessThan( strpos( $style, 'rotate' ), strpos( $style, 'fill' ) ); } + public function test_shadow_keeps_the_style_engine_order() { + $output = gutenberg_render_block_core_icon( + array( + 'icon' => 'core/info', + 'style' => array( + 'color' => array( 'text' => '#000' ), + 'border' => array( 'width' => '2px' ), + 'shadow' => 'var:preset|shadow|natural', + 'spacing' => array( 'padding' => '4px' ), + 'dimensions' => array( 'width' => '48px' ), + ), + ) + ); + + $processor = new WP_HTML_Tag_Processor( $output ); + $this->assertTrue( $processor->next_tag( 'svg' ) ); + $this->assertSame( 'has-text-color', $processor->get_attribute( 'class' ) ); + $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_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-featured-image-test.php b/phpunit/blocks/render-block-post-featured-image-test.php index ac6a17c1d977ec..f24209acc2d340 100644 --- a/phpunit/blocks/render-block-post-featured-image-test.php +++ b/phpunit/blocks/render-block-post-featured-image-test.php @@ -36,13 +36,12 @@ public static function wpTearDownAfterClass() { } /** - * Renders a Post Featured Image block and returns the class and style - * attributes of the image and the overlay. + * Renders a Post Featured Image block and returns the image's class and style attributes. * * @param array $attributes Block attributes. - * @return array Class and style of the image and the overlay. + * @return array Class and style of the image. */ - private function render_attributes( $attributes ) { + private function render_image_attributes( $attributes ) { $block = new WP_Block( array( 'blockName' => 'core/post-featured-image', @@ -53,31 +52,17 @@ private function render_attributes( $attributes ) { $processor = new WP_HTML_Tag_Processor( $block->render() ); $this->assertTrue( $processor->next_tag( 'img' ) ); - $actual = array( - 'image_class' => $processor->get_attribute( 'class' ), - 'image_style' => $processor->get_attribute( 'style' ), - ); - if ( $processor->next_tag( 'span' ) ) { - $actual['overlay_class'] = $processor->get_attribute( 'class' ); - $actual['overlay_style'] = $processor->get_attribute( 'style' ); - } - - return $actual; - } - public function test_shadow_is_applied_to_the_image() { - $actual = $this->render_attributes( - array( 'style' => array( 'shadow' => 'var:preset|shadow|natural' ) ) + return array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $processor->get_attribute( 'style' ), ); - - $this->assertSame( 'object-fit:cover;box-shadow:var(--wp--preset--shadow--natural);', $actual['image_style'] ); } - public function test_shadow_follows_border_and_dimensions_on_the_image() { - $actual = $this->render_attributes( + public function test_shadow_follows_border_on_the_image() { + $actual = $this->render_image_attributes( array( - 'dimRatio' => 50, - 'style' => array( + 'style' => array( 'border' => array( 'radius' => '10px', 'color' => '#ff0000', @@ -87,15 +72,7 @@ public function test_shadow_follows_border_and_dimensions_on_the_image() { ) ); - $this->assertSame( 'has-border-color wp-post-image', $actual['image_class'] ); - $this->assertSame( 'border-color:#ff0000;border-radius:10px;object-fit:cover;box-shadow:1px 1px 1px #000;', $actual['image_style'] ); - $this->assertSame( 'wp-block-post-featured-image__overlay has-border-color has-background-dim has-background-dim-50', $actual['overlay_class'] ); - $this->assertSame( 'border-color:#ff0000;border-radius:10px', $actual['overlay_style'] ); - } - - public function test_empty_shadow_is_ignored() { - $actual = $this->render_attributes( array( 'style' => array( 'shadow' => '' ) ) ); - - $this->assertSame( 'object-fit:cover;', $actual['image_style'] ); + $this->assertSame( 'has-border-color wp-post-image', $actual['class'] ); + $this->assertSame( 'border-color:#ff0000;border-radius:10px;object-fit:cover;box-shadow:1px 1px 1px #000;', $actual['style'] ); } } diff --git a/phpunit/blocks/render-block-search-test.php b/phpunit/blocks/render-block-search-test.php new file mode 100644 index 00000000000000..57ef338125895d --- /dev/null +++ b/phpunit/blocks/render-block-search-test.php @@ -0,0 +1,54 @@ +original_block_to_render = WP_Block_Supports::$block_to_render; + WP_Block_Supports::$block_to_render = array( + 'blockName' => 'core/search', + 'attrs' => array(), + ); + } + + public function tear_down() { + WP_Block_Supports::$block_to_render = $this->original_block_to_render; + + parent::tear_down(); + } + + public function test_shadow_follows_border_on_the_input_and_button() { + $output = gutenberg_render_block_core_search( + array( + 'label' => 'Search', + 'buttonText' => 'Search', + 'buttonPosition' => 'button-outside', + 'placeholder' => '', + 'style' => array( + 'border' => array( 'width' => '2px' ), + 'shadow' => 'var:preset|shadow|natural', + ), + ) + ); + + $processor = new WP_HTML_Tag_Processor( $output ); + $this->assertTrue( $processor->next_tag( 'input' ) ); + $this->assertSame( 'border-width: 2px;box-shadow:var(--wp--preset--shadow--natural)', $processor->get_attribute( 'style' ) ); + $this->assertTrue( $processor->next_tag( 'button' ) ); + $this->assertSame( 'border-width: 2px;box-shadow:var(--wp--preset--shadow--natural)', $processor->get_attribute( 'style' ) ); + } +} From b6775d457d40de78cf40b257d03762dba6e0dacd Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:19:30 +0800 Subject: [PATCH 06/12] Move the shadow helper to WordPress 7.3 --- backport-changelog/{7.2 => 7.3}/14094.md | 0 lib/block-supports/shadow.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename backport-changelog/{7.2 => 7.3}/14094.md (100%) diff --git a/backport-changelog/7.2/14094.md b/backport-changelog/7.3/14094.md similarity index 100% rename from backport-changelog/7.2/14094.md rename to backport-changelog/7.3/14094.md diff --git a/lib/block-supports/shadow.php b/lib/block-supports/shadow.php index 17bfc89d199cd0..a3958bf17a7efc 100644 --- a/lib/block-supports/shadow.php +++ b/lib/block-supports/shadow.php @@ -62,7 +62,7 @@ function gutenberg_apply_shadow_support( $block_type, $block_attributes ) { * `getShadowClassesAndStyles()`. 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 a2d3d668d8c4d624cbdaed5b148928f388b86d9d Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:20:40 +0800 Subject: [PATCH 07/12] Keep trunk's shadow handling in Icon and Post Navigation Link --- packages/block-library/src/icon/index.php | 26 +++++-------------- .../src/post-navigation-link/index.php | 21 +++------------ 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/packages/block-library/src/icon/index.php b/packages/block-library/src/icon/index.php index 7543283d1774ac..fe1734b7e30f5f 100644 --- a/packages/block-library/src/icon/index.php +++ b/packages/block-library/src/icon/index.php @@ -83,6 +83,9 @@ function render_block_core_icon( $attributes ) { ); } + // Shadow. + $shadow_styles = $attributes['style']['shadow'] ?? null; + // Spacing (Padding). $spacing_styles = array(); if ( isset( $attributes['style']['spacing']['padding'] ) ) { @@ -98,32 +101,15 @@ function render_block_core_icon( $attributes ) { } // Generate styles and classes. - $color_and_border_output = wp_style_engine_get_styles( + $styles = wp_style_engine_get_styles( array( 'color' => $color_styles, 'background' => $background_styles, 'border' => $border_styles, - ) - ); - $shadow_output = wp_get_shadow_classes_and_styles( $attributes ); - $dimensions_and_spacing_output = wp_style_engine_get_styles( - array( - 'dimensions' => $dimensions_styles, + 'shadow' => $shadow_styles, 'spacing' => $spacing_styles, - ) - ); - $styles = array( - 'classnames' => implode( - ' ', - array_filter( - array( - $color_and_border_output['classnames'] ?? '', - $shadow_output['class'] ?? '', - $dimensions_and_spacing_output['classnames'] ?? '', - ) - ) + 'dimensions' => $dimensions_styles, ), - 'css' => ( $color_and_border_output['css'] ?? '' ) . ( $shadow_output['style'] ?? '' ) . ( $dimensions_and_spacing_output['css'] ?? '' ), ); $svg = wp_get_icon( diff --git a/packages/block-library/src/post-navigation-link/index.php b/packages/block-library/src/post-navigation-link/index.php index c42692e5d4abb1..047b05d42d756d 100644 --- a/packages/block-library/src/post-navigation-link/index.php +++ b/packages/block-library/src/post-navigation-link/index.php @@ -215,19 +215,15 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { } } - $background_and_border_output = wp_style_engine_get_styles( + $styles = wp_style_engine_get_styles( array( 'background' => $background_styles, 'border' => $border_styles, - ) - ); - $shadow_output = wp_get_shadow_classes_and_styles( $attributes ); - $dimensions_and_spacing_output = wp_style_engine_get_styles( - array( 'dimensions' => array( 'minHeight' => $block_styles['dimensions']['minHeight'] ?? null, '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, @@ -235,16 +231,7 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { ) ); - $class_names = implode( - ' ', - array_filter( - array( - $background_and_border_output['classnames'] ?? '', - $shadow_output['class'] ?? '', - $dimensions_and_spacing_output['classnames'] ?? '', - ) - ) - ); + $class_names = $styles['classnames'] ?? ''; // The style engine only adds `has-background` for a gradient, the background block support adds it for an image too. if ( ! empty( $background_styles['backgroundImage'] ) && ! in_array( 'has-background', explode( ' ', $class_names ), true ) ) { @@ -253,7 +240,7 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { return array( 'class' => $class_names, - 'style' => ( $background_and_border_output['css'] ?? '' ) . ( $shadow_output['style'] ?? '' ) . ( $dimensions_and_spacing_output['css'] ?? '' ), + 'style' => $styles['css'] ?? '', ); } From da37ce25af5db9f6765b4c89f3b8e90f147bbb1a Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 2 Nov 2026 10:59:46 +0800 Subject: [PATCH 08/12] Return early when shadow helper attributes are not an array Matches the colour, border and background helpers, and names the helper test like theirs. --- lib/block-supports/shadow.php | 4 ++++ phpunit/block-supports/shadow-test.php | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/block-supports/shadow.php b/lib/block-supports/shadow.php index a3958bf17a7efc..42579926ce7f14 100644 --- a/lib/block-supports/shadow.php +++ b/lib/block-supports/shadow.php @@ -68,6 +68,10 @@ function gutenberg_apply_shadow_support( $block_type, $block_attributes ) { * @return array Array with `class` and `style` keys, each present only when non-empty. */ function gutenberg_get_shadow_classes_and_styles( $block_attributes ) { + if ( ! is_array( $block_attributes ) ) { + return array(); + } + $shadow = $block_attributes['style']['shadow'] ?? null; $attributes = array(); diff --git a/phpunit/block-supports/shadow-test.php b/phpunit/block-supports/shadow-test.php index 0b32cd392dd003..4b3095a5b8d117 100644 --- a/phpunit/block-supports/shadow-test.php +++ b/phpunit/block-supports/shadow-test.php @@ -117,9 +117,9 @@ public function data_generate_shadow_fixtures() { * @dataProvider data_get_shadow_classes_and_styles * * @param mixed $block_attributes Block attributes. - * @param array $expected Expected shadow classes and styles. + * @param array $expected Expected classes and styles. */ - public function test_gutenberg_get_shadow_classes_and_styles( $block_attributes, $expected ) { + public function test_get_shadow_classes_and_styles( $block_attributes, $expected ) { $this->assertSame( $expected, gutenberg_get_shadow_classes_and_styles( $block_attributes ) ); } @@ -150,6 +150,10 @@ public function data_get_shadow_classes_and_styles() { 'block_attributes' => null, 'expected' => array(), ), + 'object attributes' => array( + 'block_attributes' => (object) array( 'style' => array( 'shadow' => '1px 1px 1px #000' ) ), + 'expected' => array(), + ), ); } } From 4b9ff499b9a82e7a76228b3d618e732d1778bd0f Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 2 Nov 2026 19:37:22 +0800 Subject: [PATCH 09/12] PHPStan: Baseline the shadow helper until Core has it --- tools/phpstan/baseline.neon | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index a4d746827c5d0f..e94b14a61d265a 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -96,6 +96,12 @@ parameters: count: 1 path: ../../lib/experimental/navigation-theme-opt-in.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/avatar/index.php + - message: '#^Property WP_Comment\:\:\$comment_author_url \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -138,6 +144,12 @@ parameters: count: 1 path: ../../packages/block-library/src/latest-comments/index.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/navigation-submenu/index.php + - message: '#^Call to function is_array\(\) with array\ will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -192,6 +204,12 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/post-featured-image/index.php + - message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#' identifier: return.type @@ -228,6 +246,12 @@ parameters: count: 2 path: ../../packages/block-library/src/post-time-to-read/index.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/search/index.php + - message: '#^Parameter \#3 \$side of function apply_block_core_search_border_style expects string, null given\.$#' identifier: argument.type From bc651f037606eb40d9dea6b8d8d7262f75b5e29f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 4 Nov 2026 00:03:01 -0700 Subject: [PATCH 10/12] PHPStan: Generate the WordPress stubs from the core backport The block library calls wp_get_shadow_classes_and_styles(), which the build prefixes to gutenberg_get_shadow_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 four 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 | 24 --------------------- tools/phpstan/wordpress-stubs/composer.json | 9 ++++---- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index e94b14a61d265a..a4d746827c5d0f 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -96,12 +96,6 @@ parameters: count: 1 path: ../../lib/experimental/navigation-theme-opt-in.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/avatar/index.php - - message: '#^Property WP_Comment\:\:\$comment_author_url \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -144,12 +138,6 @@ parameters: count: 1 path: ../../packages/block-library/src/latest-comments/index.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/navigation-submenu/index.php - - message: '#^Call to function is_array\(\) with array\ will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -204,12 +192,6 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/post-featured-image/index.php - - message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#' identifier: return.type @@ -246,12 +228,6 @@ parameters: count: 2 path: ../../packages/block-library/src/post-time-to-read/index.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/search/index.php - - message: '#^Parameter \#3 \$side of function apply_block_core_search_border_style expects string, null given\.$#' identifier: argument.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 7679fd553ee426b123631dc9b352e899064cdc3c Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:17:51 +0800 Subject: [PATCH 11/12] Revert the WordPress stubs pin to Core PR 14094 This reverts commit bc651f03760, which was a2fa893ed82 before the rebase. --- tools/phpstan/baseline.neon | 24 +++++++++++++++++++++ tools/phpstan/wordpress-stubs/composer.json | 9 ++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index a4d746827c5d0f..e94b14a61d265a 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -96,6 +96,12 @@ parameters: count: 1 path: ../../lib/experimental/navigation-theme-opt-in.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/avatar/index.php + - message: '#^Property WP_Comment\:\:\$comment_author_url \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -138,6 +144,12 @@ parameters: count: 1 path: ../../packages/block-library/src/latest-comments/index.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/navigation-submenu/index.php + - message: '#^Call to function is_array\(\) with array\ will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -192,6 +204,12 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/post-featured-image/index.php + - message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#' identifier: return.type @@ -228,6 +246,12 @@ parameters: count: 2 path: ../../packages/block-library/src/post-time-to-read/index.php + - + message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/search/index.php + - message: '#^Parameter \#3 \$side of function apply_block_core_search_border_style expects string, null given\.$#' identifier: argument.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 1a3c0e7b308a5db4d726b021cea6d39e73b227c0 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:18:24 +0800 Subject: [PATCH 12/12] PHPStan: Ignore the missing wp_get_shadow_classes_and_styles() function until the stubs include it --- phpstan.neon.dist | 6 ++++++ tools/phpstan/baseline.neon | 24 ------------------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9ca9711515a713..087504b5b6c81b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -27,6 +27,12 @@ parameters: message: '#^Action callback returns .+ but should not return anything\.$#' identifier: return.void + # wp_get_shadow_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_shadow_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 e94b14a61d265a..a4d746827c5d0f 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -96,12 +96,6 @@ parameters: count: 1 path: ../../lib/experimental/navigation-theme-opt-in.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/avatar/index.php - - message: '#^Property WP_Comment\:\:\$comment_author_url \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -144,12 +138,6 @@ parameters: count: 1 path: ../../packages/block-library/src/latest-comments/index.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/navigation-submenu/index.php - - message: '#^Call to function is_array\(\) with array\ will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -204,12 +192,6 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/post-featured-image/index.php - - message: '#^Function block_core_post_time_to_read_word_count\(\) should return string but returns int\.$#' identifier: return.type @@ -246,12 +228,6 @@ parameters: count: 2 path: ../../packages/block-library/src/post-time-to-read/index.php - - - message: '#^Function wp_get_shadow_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/search/index.php - - message: '#^Parameter \#3 \$side of function apply_block_core_search_border_style expects string, null given\.$#' identifier: argument.type