From ce7d3f0dd9241bcdb8e369633c0c204ea2e0c9db Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 08:17:45 +0800 Subject: [PATCH 01/15] Border: Add a PHP helper for block support classes and styles --- lib/block-supports/border.php | 126 ++++++++----- packages/block-library/package.json | 1 + packages/block-library/src/avatar/index.php | 43 +---- packages/block-library/src/icon/index.php | 48 ++--- .../src/post-featured-image/index.php | 43 +---- .../src/post-navigation-link/index.php | 40 +--- phpunit/block-supports/border-test.php | 176 ++++++++++++++++++ phpunit/blocks/render-block-avatar-test.php | 30 +++ phpunit/blocks/render-block-icon-test.php | 34 ++++ .../render-block-post-featured-image-test.php | 50 +++++ ...render-block-post-navigation-link-test.php | 23 +++ 11 files changed, 410 insertions(+), 204 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 1c09361ba08a40..f896b42359b23c 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -44,76 +44,104 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { return array(); } - $border_block_styles = array(); $has_border_color_support = gutenberg_has_border_feature_support( $block_type, 'color' ); $has_border_width_support = gutenberg_has_border_feature_support( $block_type, 'width' ); + $border = isset( $block_attributes['style']['border'] ) && is_array( $block_attributes['style']['border'] ) + ? $block_attributes['style']['border'] + : array(); + $border_attributes = array(); + $border_styles = array(); + + foreach ( array( 'radius', 'style', 'width', 'color' ) as $feature ) { + if ( + isset( $border[ $feature ] ) && + gutenberg_has_border_feature_support( $block_type, $feature ) && + ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) + ) { + $border_styles[ $feature ] = $border[ $feature ]; + } + } - // Border radius. if ( - gutenberg_has_border_feature_support( $block_type, 'radius' ) && - isset( $block_attributes['style']['border']['radius'] ) && - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' ) + $has_border_color_support && + array_key_exists( 'borderColor', $block_attributes ) && + ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ) { - $border_radius = $block_attributes['style']['border']['radius']; + $border_attributes['borderColor'] = $block_attributes['borderColor']; + } - if ( is_numeric( $border_radius ) ) { - $border_radius .= 'px'; + // Side values are filtered by skipped serialization only, not by feature support. + if ( $has_border_color_support || $has_border_width_support ) { + foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { + if ( ! isset( $border[ $side ] ) || ! is_array( $border[ $side ] ) ) { + continue; + } + $border_styles[ $side ] = $border[ $side ]; + foreach ( array( 'width', 'color', 'style' ) as $feature ) { + if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { + unset( $border_styles[ $side ][ $feature ] ); + } + } } - - $border_block_styles['radius'] = $border_radius; } - // Border style. - if ( - gutenberg_has_border_feature_support( $block_type, 'style' ) && - isset( $block_attributes['style']['border']['style'] ) && - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) - ) { - $border_block_styles['style'] = $block_attributes['style']['border']['style']; + $border_attributes['style'] = array( 'border' => $border_styles ); + + return gutenberg_get_border_classes_and_styles( $border_attributes ); +} + +/** + * Generates border classes and inline styles from block attributes, the PHP + * twin of the JS `getBorderClassesAndStyles()`. + * + * Block support and skipped serialization are not checked: the caller passes + * only the border values it applies. + * + * @since 7.2.0 + * + * @param array $block_attributes Block attributes. + * + * @return array Border CSS classes and inline styles. + */ +function gutenberg_get_border_classes_and_styles( $block_attributes ) { + if ( ! is_array( $block_attributes ) ) { + return array(); } - // Border width. - if ( - $has_border_width_support && - isset( $block_attributes['style']['border']['width'] ) && - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) - ) { - $border_width = $block_attributes['style']['border']['width']; + $border = isset( $block_attributes['style']['border'] ) && is_array( $block_attributes['style']['border'] ) + ? $block_attributes['style']['border'] + : array(); + $border_styles = array(); - // This check handles original unitless implementation. - if ( is_numeric( $border_width ) ) { - $border_width .= 'px'; - } + // Radius and width accept unitless numbers from the original implementation. + if ( isset( $border['radius'] ) ) { + $border_styles['radius'] = is_numeric( $border['radius'] ) ? "{$border['radius']}px" : $border['radius']; + } - $border_block_styles['width'] = $border_width; + if ( isset( $border['style'] ) ) { + $border_styles['style'] = $border['style']; } - // Border color. - if ( - $has_border_color_support && - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) - ) { - $preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null; - $custom_border_color = $block_attributes['style']['border']['color'] ?? null; - $border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color; + if ( isset( $border['width'] ) ) { + $border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width']; } - // Generate styles for individual border sides. - if ( $has_border_color_support || $has_border_width_support ) { - foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { - $border = $block_attributes['style']['border'][ $side ] ?? null; - $border_side_values = array( - 'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null, - 'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null, - 'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null, - ); - $border_block_styles[ $side ] = $border_side_values; + $preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null; + $border_styles['color'] = $preset_border_color ? $preset_border_color : ( $border['color'] ?? null ); + + foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { + if ( ! isset( $border[ $side ] ) || ! is_array( $border[ $side ] ) ) { + continue; } + $border_styles[ $side ] = array( + 'width' => $border[ $side ]['width'] ?? null, + 'color' => $border[ $side ]['color'] ?? null, + 'style' => $border[ $side ]['style'] ?? null, + ); } - // Collect classes and styles. $attributes = array(); - $styles = gutenberg_style_engine_get_styles( array( 'border' => $border_block_styles ) ); + $styles = gutenberg_style_engine_get_styles( array( 'border' => $border_styles ) ); if ( ! empty( $styles['classnames'] ) ) { $attributes['class'] = $styles['classnames']; diff --git a/packages/block-library/package.json b/packages/block-library/package.json index f41612153347f3..1a386bceb00bc6 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -70,6 +70,7 @@ "prefixFunctions": [ "wp_apply_colors_support", "wp_get_color_classes_and_styles", + "wp_get_border_classes_and_styles", "wp_enqueue_block_support_styles", "wp_get_typography_font_size_value", "wp_get_shadow_classes_and_styles", diff --git a/packages/block-library/src/avatar/index.php b/packages/block-library/src/avatar/index.php index 0f56ce461a08f6..f7206c14119ec9 100644 --- a/packages/block-library/src/avatar/index.php +++ b/packages/block-library/src/avatar/index.php @@ -108,48 +108,7 @@ function render_block_core_avatar( $attributes, $content, $block ) { * @return array The border-related classnames and styles for the block. */ function get_block_core_avatar_border_attributes( $attributes ) { - $border_styles = array(); - $sides = array( 'top', 'right', 'bottom', 'left' ); - - // Border radius. - if ( isset( $attributes['style']['border']['radius'] ) ) { - $border_styles['radius'] = $attributes['style']['border']['radius']; - } - - // Border style. - if ( isset( $attributes['style']['border']['style'] ) ) { - $border_styles['style'] = $attributes['style']['border']['style']; - } - - // Border width. - if ( isset( $attributes['style']['border']['width'] ) ) { - $border_styles['width'] = $attributes['style']['border']['width']; - } - - // Border color. - $preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; - $custom_color = $attributes['style']['border']['color'] ?? null; - $border_styles['color'] = $preset_color ? $preset_color : $custom_color; - - // Individual border styles e.g. top, left etc. - foreach ( $sides as $side ) { - $border = $attributes['style']['border'][ $side ] ?? null; - $border_styles[ $side ] = array( - 'color' => $border['color'] ?? null, - 'style' => $border['style'] ?? null, - 'width' => $border['width'] ?? null, - ); - } - - $styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) ); - $attributes = array(); - if ( ! empty( $styles['classnames'] ) ) { - $attributes['class'] = $styles['classnames']; - } - if ( ! empty( $styles['css'] ) ) { - $attributes['style'] = $styles['css']; - } - return $attributes; + return wp_get_border_classes_and_styles( $attributes ); } /** diff --git a/packages/block-library/src/icon/index.php b/packages/block-library/src/icon/index.php index 017d3d90bbec9e..f06330bfd72257 100644 --- a/packages/block-library/src/icon/index.php +++ b/packages/block-library/src/icon/index.php @@ -46,33 +46,6 @@ function render_block_core_icon( $attributes ) { } $background_styles = wp_get_background_classes_and_styles( array( 'style' => array( 'background' => $background ) ) ); - // Border. - $border_styles = array(); - $sides = array( 'top', 'right', 'bottom', 'left' ); - - if ( isset( $attributes['style']['border']['radius'] ) ) { - $border_styles['radius'] = $attributes['style']['border']['radius']; - } - if ( isset( $attributes['style']['border']['style'] ) ) { - $border_styles['style'] = $attributes['style']['border']['style']; - } - if ( isset( $attributes['style']['border']['width'] ) ) { - $border_styles['width'] = $attributes['style']['border']['width']; - } - - $preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; - $custom_color = $attributes['style']['border']['color'] ?? null; - $border_styles['color'] = $preset_color ? $preset_color : $custom_color; - - foreach ( $sides as $side ) { - $border = $attributes['style']['border'][ $side ] ?? null; - $border_styles[ $side ] = array( - 'color' => $border['color'] ?? null, - 'style' => $border['style'] ?? null, - 'width' => $border['width'] ?? null, - ); - } - // Shadow. $shadow_styles = $attributes['style']['shadow'] ?? null; @@ -84,16 +57,16 @@ function render_block_core_icon( $attributes ) { } } - // Generate styles and classes. - $styles = wp_style_engine_get_styles( + // Border sits between color and shadow in the style engine's order. + $styles_before_border = wp_style_engine_get_styles( array( 'color' => $color_styles ) ); + $border_styles = wp_get_border_classes_and_styles( $attributes ); + $styles_after_border = wp_style_engine_get_styles( array( - 'color' => $color_styles, - 'border' => $border_styles, 'shadow' => $shadow_styles, 'dimensions' => $dimensions_styles, - ), + ) ); - $spacing_styles = wp_get_spacing_classes_and_styles( + $spacing_styles = wp_get_spacing_classes_and_styles( array( 'style' => array( 'spacing' => array( @@ -102,17 +75,20 @@ function render_block_core_icon( $attributes ) { ), ) ); - $styles['css'] = ( $styles['css'] ?? '' ) . ( $spacing_styles['style'] ?? '' ); + $styles = array( + 'classnames' => implode( ' ', array_filter( array( $styles_before_border['classnames'] ?? '', $border_styles['class'] ?? '', $styles_after_border['classnames'] ?? '' ) ) ), + 'css' => ( $styles_before_border['css'] ?? '' ) . ( $border_styles['style'] ?? '' ) . ( $styles_after_border['css'] ?? '' ) . ( $spacing_styles['style'] ?? '' ), + ); // The style engine outputs background before the other groups, so it leads here too. - $css = ( $background_styles['style'] ?? '' ) . ( $styles['css'] ?? '' ); + $css = ( $background_styles['style'] ?? '' ) . $styles['css']; $svg = wp_get_icon( $attributes['icon'], array( // Width is applied via the dimensions block support styles below. 'size' => null, - 'class' => $styles['classnames'] ?? '', + 'class' => $styles['classnames'], 'label' => $attributes['ariaLabel'] ?? '', ) ); diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php index 08ac73adff0705..7b4c568f4cb0a1 100644 --- a/packages/block-library/src/post-featured-image/index.php +++ b/packages/block-library/src/post-featured-image/index.php @@ -209,48 +209,7 @@ function get_block_core_post_featured_image_overlay_element_markup( $attributes * @return array The border-related classnames and styles for the block. */ function get_block_core_post_featured_image_border_attributes( $attributes ) { - $border_styles = array(); - $sides = array( 'top', 'right', 'bottom', 'left' ); - - // Border radius. - if ( isset( $attributes['style']['border']['radius'] ) ) { - $border_styles['radius'] = $attributes['style']['border']['radius']; - } - - // Border style. - if ( isset( $attributes['style']['border']['style'] ) ) { - $border_styles['style'] = $attributes['style']['border']['style']; - } - - // Border width. - if ( isset( $attributes['style']['border']['width'] ) ) { - $border_styles['width'] = $attributes['style']['border']['width']; - } - - // Border color. - $preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; - $custom_color = $attributes['style']['border']['color'] ?? null; - $border_styles['color'] = $preset_color ? $preset_color : $custom_color; - - // Individual border styles e.g. top, left etc. - foreach ( $sides as $side ) { - $border = $attributes['style']['border'][ $side ] ?? null; - $border_styles[ $side ] = array( - 'color' => $border['color'] ?? null, - 'style' => $border['style'] ?? null, - 'width' => $border['width'] ?? null, - ); - } - - $styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) ); - $attributes = array(); - if ( ! empty( $styles['classnames'] ) ) { - $attributes['class'] = $styles['classnames']; - } - if ( ! empty( $styles['css'] ) ) { - $attributes['style'] = $styles['css']; - } - return $attributes; + return wp_get_border_classes_and_styles( $attributes ); } /** diff --git a/packages/block-library/src/post-navigation-link/index.php b/packages/block-library/src/post-navigation-link/index.php index 8e61b4fbbd4850..79ebc4c16025d7 100644 --- a/packages/block-library/src/post-navigation-link/index.php +++ b/packages/block-library/src/post-navigation-link/index.php @@ -166,38 +166,8 @@ function render_block_core_post_navigation_link( $attributes, $content ) { * } */ function block_core_post_navigation_link_get_support_styles( $attributes ) { - $block_styles = $attributes['style'] ?? array(); - $border = $block_styles['border'] ?? array(); - $border_styles = array(); - - // Border radius and width accept unitless numbers from the original implementation. - if ( isset( $border['radius'] ) ) { - $border_styles['radius'] = is_numeric( $border['radius'] ) ? "{$border['radius']}px" : $border['radius']; - } - - if ( isset( $border['width'] ) ) { - $border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width']; - } - - if ( isset( $border['style'] ) ) { - $border_styles['style'] = $border['style']; - } - - // A preset border color is stored in its own attribute rather than under `style`. - $border_styles['color'] = isset( $attributes['borderColor'] ) - ? "var:preset|color|{$attributes['borderColor']}" - : ( $border['color'] ?? null ); - - // Individual border sides e.g. top, left etc. - foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { - $border_styles[ $side ] = array( - 'width' => $border[ $side ]['width'] ?? null, - 'color' => $border[ $side ]['color'] ?? null, - 'style' => $border[ $side ]['style'] ?? null, - ); - } - - $background = $block_styles['background'] ?? null; + $block_styles = $attributes['style'] ?? array(); + $background = $block_styles['background'] ?? null; // Post Navigation Link has no clip support, so ignore a stale value. if ( is_array( $background ) ) { @@ -205,10 +175,10 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { } $background_styles = wp_get_background_classes_and_styles( array( 'style' => array( 'background' => $background ) ) ); + $border_styles = wp_get_border_classes_and_styles( $attributes ); $styles = wp_style_engine_get_styles( array( - 'border' => $border_styles, 'dimensions' => array( 'minHeight' => $block_styles['dimensions']['minHeight'] ?? null, 'minWidth' => $block_styles['dimensions']['minWidth'] ?? null, @@ -220,8 +190,8 @@ function block_core_post_navigation_link_get_support_styles( $attributes ) { // The style engine outputs background before the other groups, so it leads here too. return array( - 'class' => trim( ( $background_styles['class'] ?? '' ) . ' ' . ( $styles['classnames'] ?? '' ) ), - 'style' => ( $background_styles['style'] ?? '' ) . ( $styles['css'] ?? '' ) . ( $spacing_styles['style'] ?? '' ), + 'class' => implode( ' ', array_filter( array( $background_styles['class'] ?? '', $border_styles['class'] ?? '', $styles['classnames'] ?? '' ) ) ), + 'style' => ( $background_styles['style'] ?? '' ) . ( $border_styles['style'] ?? '' ) . ( $styles['css'] ?? '' ) . ( $spacing_styles['style'] ?? '' ), ); } diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index d6e98314effc60..4ed0941e355a04 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -458,4 +458,180 @@ public function test_split_borders_with_named_colors() { $this->assertSame( $expected, $actual ); } + + public function test_split_borders_with_color_support_only_keep_side_style() { + $block_type = self::register_bordered_block_with_support( + 'test/split-borders-with-color-support-only', + array( + '__experimentalBorder' => array( + 'color' => true, + ), + ) + ); + $block_attrs = array( + 'style' => array( + 'border' => array( + 'style' => 'solid', + 'top' => array( + 'color' => '#72aee6', + 'style' => 'dashed', + ), + ), + ), + ); + $actual = gutenberg_apply_border_support( $block_type, $block_attrs ); + $expected = array( + 'style' => 'border-top-color:#72aee6;border-top-style:dashed;', + ); + + $this->assertSame( $expected, $actual ); + } + + public function test_split_borders_with_width_support_only_keep_side_color() { + $block_type = self::register_bordered_block_with_support( + 'test/split-borders-with-width-support-only', + array( + '__experimentalBorder' => array( + 'width' => true, + ), + ) + ); + $block_attrs = array( + 'borderColor' => 'red', + 'style' => array( + 'border' => array( + 'top' => array( + 'color' => '#72aee6', + 'width' => '2px', + ), + ), + ), + ); + $actual = gutenberg_apply_border_support( $block_type, $block_attrs ); + $expected = array( + 'style' => 'border-top-width:2px;border-top-color:#72aee6;', + ); + + $this->assertSame( $expected, $actual ); + } + + /** + * @dataProvider data_get_border_classes_and_styles + * + * @param mixed $block_attributes Block attributes. + * @param array $expected Expected classes and styles. + */ + public function test_get_border_classes_and_styles( $block_attributes, $expected ) { + $this->assertSame( $expected, gutenberg_get_border_classes_and_styles( $block_attributes ) ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_get_border_classes_and_styles() { + return array( + 'custom' => array( + 'block_attributes' => array( + 'style' => array( + 'border' => array( + 'radius' => '10px', + 'style' => 'solid', + 'width' => '2px', + 'color' => '#ff0000', + 'top' => array( + 'style' => 'dashed', + 'color' => '#00ff00', + 'width' => '3px', + ), + ), + ), + ), + 'expected' => array( + 'class' => 'has-border-color', + 'style' => 'border-color:#ff0000;border-radius:10px;border-style:solid;border-width:2px;border-top-width:3px;border-top-color:#00ff00;border-top-style:dashed;', + ), + ), + 'preset' => array( + 'block_attributes' => array( + 'borderColor' => 'red', + 'style' => array( + 'border' => array( + 'color' => '#ff0000', + ), + ), + ), + 'expected' => array( + 'class' => 'has-border-color has-red-border-color', + ), + ), + 'preset only' => array( + 'block_attributes' => array( + 'borderColor' => 'red', + ), + 'expected' => array( + 'class' => 'has-border-color has-red-border-color', + ), + ), + 'numeric' => array( + 'block_attributes' => array( + 'style' => array( + 'border' => array( + 'radius' => 5, + 'width' => 2, + ), + ), + ), + 'expected' => array( + 'style' => 'border-radius:5px;border-width:2px;', + ), + ), + 'zero' => array( + 'block_attributes' => array( + 'style' => array( + 'border' => array( + 'radius' => 0, + 'width' => 0, + ), + ), + ), + 'expected' => array( + 'style' => 'border-radius:0px;border-width:0px;', + ), + ), + 'empty' => array( + 'block_attributes' => array(), + 'expected' => array(), + ), + 'malformed border' => array( + 'block_attributes' => array( + 'style' => array( + 'border' => 'solid', + ), + ), + 'expected' => array(), + ), + 'malformed side' => array( + 'block_attributes' => array( + 'style' => array( + 'border' => array( + 'top' => '1px solid', + ), + ), + ), + 'expected' => array(), + ), + 'malformed style' => array( + 'block_attributes' => array( + 'style' => 'border:1px solid', + ), + 'expected' => array(), + ), + 'malformed non-array' => array( + 'block_attributes' => 'border', + 'expected' => array(), + ), + ); + } } diff --git a/phpunit/blocks/render-block-avatar-test.php b/phpunit/blocks/render-block-avatar-test.php index 02bf59ae98a297..63289924df169a 100644 --- a/phpunit/blocks/render-block-avatar-test.php +++ b/phpunit/blocks/render-block-avatar-test.php @@ -64,4 +64,34 @@ 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_image_border_and_shadow_styles() { + $attributes = array( + 'userId' => self::$user_id, + 'borderColor' => 'accent-2', + 'style' => array( + 'border' => array( + 'radius' => 5, + 'top' => array( + 'style' => 'dashed', + 'width' => '3px', + ), + ), + 'shadow' => '10px 10px 5px #000000', + ), + ); + + $processor = new WP_HTML_Tag_Processor( do_blocks( '' ) ); + $this->assertTrue( $processor->next_tag( 'img' ) ); + $this->assertSame( + array( + 'class' => 'avatar avatar-96 photo wp-block-avatar__image has-border-color has-accent-2-border-color', + 'style' => 'border-radius:5px;border-top-width:3px;border-top-style:dashed;box-shadow:10px 10px 5px #000000;', + ), + array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $processor->get_attribute( 'style' ), + ) + ); + } } diff --git a/phpunit/blocks/render-block-icon-test.php b/phpunit/blocks/render-block-icon-test.php index b49d25ece90812..bc54e04777a060 100644 --- a/phpunit/blocks/render-block-icon-test.php +++ b/phpunit/blocks/render-block-icon-test.php @@ -193,6 +193,40 @@ public function test_background_ignores_clip() { $this->assertTrue( $processor->has_class( 'has-background' ) ); } + public function test_border_styles_sit_between_color_and_dimensions() { + $attributes = array( + 'icon' => 'core/caution', + 'textColor' => 'vivid-red', + 'borderColor' => 'accent-2', + 'style' => array( + 'color' => array( 'background' => '#eeeeee' ), + 'border' => array( + 'radius' => 5, + 'top' => array( + 'style' => 'dashed', + 'width' => '3px', + ), + ), + 'shadow' => '10px 10px 5px #000000', + 'dimensions' => array( 'width' => '48px' ), + 'spacing' => array( 'padding' => array( 'top' => '4px' ) ), + ), + ); + + $processor = new WP_HTML_Tag_Processor( gutenberg_render_block_core_icon( $attributes ) ); + $this->assertTrue( $processor->next_tag( 'svg' ) ); + $this->assertSame( + array( + 'class' => 'has-text-color has-vivid-red-color has-background has-border-color has-accent-2-border-color', + 'style' => 'fill: none; color:var(--wp--preset--color--vivid-red);background-color:#eeeeee;border-radius:5px;border-top-width:3px;border-top-style:dashed;box-shadow:10px 10px 5px #000000;width:48px;padding-top:4px;', + ), + array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $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 f24209acc2d340..7e266b627c7a5f 100644 --- a/phpunit/blocks/render-block-post-featured-image-test.php +++ b/phpunit/blocks/render-block-post-featured-image-test.php @@ -75,4 +75,54 @@ public function test_shadow_follows_border_on_the_image() { $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'] ); } + + public function test_image_and_overlay_border_styles() { + $block = new WP_Block( + array( + 'blockName' => 'core/post-featured-image', + 'attrs' => array( + 'dimRatio' => 50, + 'borderColor' => 'accent-2', + 'style' => array( + 'border' => array( + 'radius' => 5, + 'top' => array( + 'style' => 'dashed', + 'width' => '3px', + ), + ), + 'shadow' => '10px 10px 5px #000000', + ), + ), + ), + array( 'postId' => self::$post_id ) + ); + + $processor = new WP_HTML_Tag_Processor( $block->render() ); + $this->assertTrue( $processor->next_tag( 'img' ) ); + $image = array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $processor->get_attribute( 'style' ), + ); + $this->assertTrue( $processor->next_tag( 'span' ) ); + $overlay = array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $processor->get_attribute( 'style' ), + ); + + $this->assertSame( + array( + 'class' => 'has-border-color has-accent-2-border-color wp-post-image', + 'style' => 'border-radius:5px;border-top-width:3px;border-top-style:dashed;object-fit:cover;box-shadow:10px 10px 5px #000000;', + ), + $image + ); + $this->assertSame( + array( + 'class' => 'wp-block-post-featured-image__overlay has-border-color has-accent-2-border-color has-background-dim has-background-dim-50', + 'style' => 'border-radius:5px;border-top-width:3px;border-top-style:dashed', + ), + $overlay + ); + } } diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php index 5626e23b9a4437..ff50ba0379849a 100644 --- a/phpunit/blocks/render-block-post-navigation-link-test.php +++ b/phpunit/blocks/render-block-post-navigation-link-test.php @@ -129,6 +129,29 @@ public function test_rendered_link_includes_border_dimensions_shadow_and_spacing $this->assertStringContainsString( 'has-accent-2-border-color', $output ); } + public function test_rendered_link_support_styles_full_markup() { + $attributes = $this->styled_attributes(); + $attributes['style']['border']['radius'] = 5; + $attributes['style']['border']['top'] = array( + 'width' => '4px', + 'color' => '#ff0000', + 'style' => 'solid', + ); + + $processor = new WP_HTML_Tag_Processor( $this->render_block( self::$second_post_id, $attributes ) ); + $this->assertTrue( $processor->next_tag( 'div' ) ); + $this->assertSame( + array( + 'class' => 'post-navigation-link-previous has-border-color has-accent-2-border-color wp-block-post-navigation-link', + 'style' => 'border-radius:5px;border-style:dashed;border-width:3px;border-top-width:4px;border-top-color:#ff0000;border-top-style:solid;box-shadow:10px 10px 5px #000000;padding-top:20px;margin-top:30px', + ), + array( + 'class' => $processor->get_attribute( 'class' ), + 'style' => $processor->get_attribute( 'style' ), + ) + ); + } + public function test_individual_border_sides_match_the_core_declaration_order() { $attributes = array( 'type' => 'previous', From 58ed19e7b36c563a88d6a2f9d1761241cb11aeaa Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:13:21 +0800 Subject: [PATCH 02/15] Address review feedback --- lib/block-supports/border.php | 31 ++++++++--------- phpunit/block-supports/border-test.php | 46 +++++++++++++++++++------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index f896b42359b23c..2eaa5b9192ec45 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -70,17 +70,17 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { $border_attributes['borderColor'] = $block_attributes['borderColor']; } - // Side values are filtered by skipped serialization only, not by feature support. + // Sides are filtered by skipped serialization only, not by feature support. if ( $has_border_color_support || $has_border_width_support ) { - foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { - if ( ! isset( $border[ $side ] ) || ! is_array( $border[ $side ] ) ) { - continue; + $skipped_side_features = array(); + foreach ( array( 'width', 'color', 'style' ) as $feature ) { + if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { + $skipped_side_features[ $feature ] = true; } - $border_styles[ $side ] = $border[ $side ]; - foreach ( array( 'width', 'color', 'style' ) as $feature ) { - if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { - unset( $border_styles[ $side ][ $feature ] ); - } + } + foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { + if ( isset( $border[ $side ] ) && is_array( $border[ $side ] ) ) { + $border_styles[ $side ] = array_diff_key( $border[ $side ], $skipped_side_features ); } } } @@ -91,17 +91,14 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { } /** - * Generates border classes and inline styles from block attributes, the PHP - * twin of the JS `getBorderClassesAndStyles()`. - * - * Block support and skipped serialization are not checked: the caller passes - * only the border values it applies. + * Returns border classes and inline styles for block attributes, like the JS + * `getBorderClassesAndStyles()`. Does not check block support or skipped + * serialization. * * @since 7.2.0 * * @param array $block_attributes Block attributes. - * - * @return array Border CSS classes and inline styles. + * @return array Array with `class` and `style` keys, each present only when non-empty. */ function gutenberg_get_border_classes_and_styles( $block_attributes ) { if ( ! is_array( $block_attributes ) ) { @@ -113,7 +110,7 @@ function gutenberg_get_border_classes_and_styles( $block_attributes ) { : array(); $border_styles = array(); - // Radius and width accept unitless numbers from the original implementation. + // Unitless radius and width are from the original implementation. if ( isset( $border['radius'] ) ) { $border_styles['radius'] = is_numeric( $border['radius'] ) ? "{$border['radius']}px" : $border['radius']; } diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index 4ed0941e355a04..2fd9326bdeb7a6 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -184,6 +184,28 @@ public function test_flat_border_with_individual_skipped_serialization() { $this->assertSame( $expected, $actual ); } + public function test_border_color_preset_with_skipped_color_serialization() { + $block_type = self::register_bordered_block_with_support( + 'test/border-color-preset-with-skipped-color-serialization', + array( + '__experimentalBorder' => array( + 'color' => true, + 'width' => true, + '__experimentalSkipSerialization' => array( 'color' ), + ), + ) + ); + $block_attrs = array( + 'borderColor' => 'red', + 'style' => array( 'border' => array( 'width' => '1px' ) ), + ); + + $this->assertSame( + array( 'style' => 'border-width:1px;' ), + gutenberg_apply_border_support( $block_type, $block_attrs ) + ); + } + public function test_split_border_radius() { $block_type = self::register_bordered_block_with_support( 'test/split-border-radius', @@ -459,7 +481,7 @@ public function test_split_borders_with_named_colors() { $this->assertSame( $expected, $actual ); } - public function test_split_borders_with_color_support_only_keep_side_style() { + public function test_split_borders_with_color_support_only_keeps_side_style() { $block_type = self::register_bordered_block_with_support( 'test/split-borders-with-color-support-only', array( @@ -487,7 +509,7 @@ public function test_split_borders_with_color_support_only_keep_side_style() { $this->assertSame( $expected, $actual ); } - public function test_split_borders_with_width_support_only_keep_side_color() { + public function test_split_borders_with_width_support_only_keeps_side_color() { $block_type = self::register_bordered_block_with_support( 'test/split-borders-with-width-support-only', array( @@ -532,7 +554,7 @@ public function test_get_border_classes_and_styles( $block_attributes, $expected */ public function data_get_border_classes_and_styles() { return array( - 'custom' => array( + 'custom' => array( 'block_attributes' => array( 'style' => array( 'border' => array( @@ -553,7 +575,7 @@ public function data_get_border_classes_and_styles() { 'style' => 'border-color:#ff0000;border-radius:10px;border-style:solid;border-width:2px;border-top-width:3px;border-top-color:#00ff00;border-top-style:dashed;', ), ), - 'preset' => array( + 'preset wins over custom' => array( 'block_attributes' => array( 'borderColor' => 'red', 'style' => array( @@ -566,7 +588,7 @@ public function data_get_border_classes_and_styles() { 'class' => 'has-border-color has-red-border-color', ), ), - 'preset only' => array( + 'preset only' => array( 'block_attributes' => array( 'borderColor' => 'red', ), @@ -574,7 +596,7 @@ public function data_get_border_classes_and_styles() { 'class' => 'has-border-color has-red-border-color', ), ), - 'numeric' => array( + 'numeric' => array( 'block_attributes' => array( 'style' => array( 'border' => array( @@ -587,7 +609,7 @@ public function data_get_border_classes_and_styles() { 'style' => 'border-radius:5px;border-width:2px;', ), ), - 'zero' => array( + 'zero' => array( 'block_attributes' => array( 'style' => array( 'border' => array( @@ -600,11 +622,11 @@ public function data_get_border_classes_and_styles() { 'style' => 'border-radius:0px;border-width:0px;', ), ), - 'empty' => array( + 'empty' => array( 'block_attributes' => array(), 'expected' => array(), ), - 'malformed border' => array( + 'malformed border' => array( 'block_attributes' => array( 'style' => array( 'border' => 'solid', @@ -612,7 +634,7 @@ public function data_get_border_classes_and_styles() { ), 'expected' => array(), ), - 'malformed side' => array( + 'malformed side' => array( 'block_attributes' => array( 'style' => array( 'border' => array( @@ -622,13 +644,13 @@ public function data_get_border_classes_and_styles() { ), 'expected' => array(), ), - 'malformed style' => array( + 'malformed style' => array( 'block_attributes' => array( 'style' => 'border:1px solid', ), 'expected' => array(), ), - 'malformed non-array' => array( + 'malformed non-array' => array( 'block_attributes' => 'border', 'expected' => array(), ), From 4f7ffee9d4e8ba0c9b7cd6c40392e4211be77001 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/15] 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 1cc49378ae7b2d28048ef1274856e50927eb7c27 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 21:17:24 +0800 Subject: [PATCH 04/15] Filter by removing values before calling the helper --- lib/block-supports/border.php | 55 ++++++++++++++------------ phpunit/block-supports/border-test.php | 55 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 26 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 2eaa5b9192ec45..5b9c39096fde5f 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -46,48 +46,51 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { $has_border_color_support = gutenberg_has_border_feature_support( $block_type, 'color' ); $has_border_width_support = gutenberg_has_border_feature_support( $block_type, 'width' ); - $border = isset( $block_attributes['style']['border'] ) && is_array( $block_attributes['style']['border'] ) - ? $block_attributes['style']['border'] - : array(); - $border_attributes = array(); - $border_styles = array(); + $attributes = $block_attributes; + + if ( ! isset( $attributes['style']['border'] ) || ! is_array( $attributes['style']['border'] ) ) { + unset( $attributes['style'] ); + } foreach ( array( 'radius', 'style', 'width', 'color' ) as $feature ) { if ( - isset( $border[ $feature ] ) && - gutenberg_has_border_feature_support( $block_type, $feature ) && - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) + ! gutenberg_has_border_feature_support( $block_type, $feature ) || + wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { - $border_styles[ $feature ] = $border[ $feature ]; + unset( $attributes['style']['border'][ $feature ] ); } } if ( - $has_border_color_support && - array_key_exists( 'borderColor', $block_attributes ) && - ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) + ! $has_border_color_support || + wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ) { - $border_attributes['borderColor'] = $block_attributes['borderColor']; + unset( $attributes['borderColor'] ); } // Sides are filtered by skipped serialization only, not by feature support. - if ( $has_border_color_support || $has_border_width_support ) { - $skipped_side_features = array(); - foreach ( array( 'width', 'color', 'style' ) as $feature ) { - if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { - $skipped_side_features[ $feature ] = true; - } - } - foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { - if ( isset( $border[ $side ] ) && is_array( $border[ $side ] ) ) { - $border_styles[ $side ] = array_diff_key( $border[ $side ], $skipped_side_features ); - } + $skipped_side_features = array(); + foreach ( array( 'width', 'color', 'style' ) as $feature ) { + if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { + $skipped_side_features[] = $feature; } } - $border_attributes['style'] = array( 'border' => $border_styles ); + foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { + if ( + ! ( $has_border_color_support || $has_border_width_support ) || + ! isset( $attributes['style']['border'][ $side ] ) || + ! is_array( $attributes['style']['border'][ $side ] ) + ) { + unset( $attributes['style']['border'][ $side ] ); + continue; + } + foreach ( $skipped_side_features as $feature ) { + unset( $attributes['style']['border'][ $side ][ $feature ] ); + } + } - return gutenberg_get_border_classes_and_styles( $border_attributes ); + return gutenberg_get_border_classes_and_styles( $attributes ); } /** diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index 2fd9326bdeb7a6..7e4ed686d715bc 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -537,6 +537,61 @@ public function test_split_borders_with_width_support_only_keeps_side_color() { $this->assertSame( $expected, $actual ); } + public function test_split_borders_without_color_or_width_support_are_dropped() { + $block_type = self::register_bordered_block_with_support( + 'test/split-borders-without-color-or-width-support', + array( + '__experimentalBorder' => array( + 'radius' => true, + 'style' => true, + ), + ) + ); + $block_attrs = array( + 'style' => array( + 'border' => array( + 'radius' => '5px', + 'top' => array( + 'style' => 'dashed', + 'width' => '2px', + ), + ), + ), + ); + $actual = gutenberg_apply_border_support( $block_type, $block_attrs ); + $expected = array( + 'style' => 'border-radius:5px;', + ); + + $this->assertSame( $expected, $actual ); + } + + public function test_non_array_border_and_sides_are_ignored() { + $block_type = self::register_bordered_block_with_support( + 'test/non-array-border-and-sides', + array( + '__experimentalBorder' => true, + ) + ); + + $this->assertSame( array(), gutenberg_apply_border_support( $block_type, array( 'style' => 'invalid' ) ) ); + $this->assertSame( array(), gutenberg_apply_border_support( $block_type, array( 'style' => array( 'border' => 'invalid' ) ) ) ); + $this->assertSame( + array( 'style' => 'border-bottom-width:1px;' ), + gutenberg_apply_border_support( + $block_type, + array( + 'style' => array( + 'border' => array( + 'top' => 'invalid', + 'bottom' => array( 'width' => '1px' ), + ), + ), + ) + ) + ); + } + /** * @dataProvider data_get_border_classes_and_styles * From 1d2806182cf82c815b1452daae26cc7dba74ffbc Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 22:05:34 +0800 Subject: [PATCH 05/15] Use named support and skip variables, and filter the attributes in place --- lib/block-supports/border.php | 70 +++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 5b9c39096fde5f..3a6cd726d71542 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -44,53 +44,59 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { return array(); } - $has_border_color_support = gutenberg_has_border_feature_support( $block_type, 'color' ); - $has_border_width_support = gutenberg_has_border_feature_support( $block_type, 'width' ); - $attributes = $block_attributes; + $has_border_color_support = gutenberg_has_border_feature_support( $block_type, 'color' ); + $has_border_radius_support = gutenberg_has_border_feature_support( $block_type, 'radius' ); + $has_border_style_support = gutenberg_has_border_feature_support( $block_type, 'style' ); + $has_border_width_support = gutenberg_has_border_feature_support( $block_type, 'width' ); + $skip_color = wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ); + $skip_radius = wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' ); + $skip_style = wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ); + $skip_width = wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ); - if ( ! isset( $attributes['style']['border'] ) || ! is_array( $attributes['style']['border'] ) ) { - unset( $attributes['style'] ); + // The helper reads only `style.border`, so a non-array value counts as no border styles. + if ( ! isset( $block_attributes['style']['border'] ) || ! is_array( $block_attributes['style']['border'] ) ) { + unset( $block_attributes['style'] ); } - foreach ( array( 'radius', 'style', 'width', 'color' ) as $feature ) { - if ( - ! gutenberg_has_border_feature_support( $block_type, $feature ) || - wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) - ) { - unset( $attributes['style']['border'][ $feature ] ); - } + if ( ! $has_border_radius_support || $skip_radius ) { + unset( $block_attributes['style']['border']['radius'] ); } - if ( - ! $has_border_color_support || - wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) - ) { - unset( $attributes['borderColor'] ); + if ( ! $has_border_style_support || $skip_style ) { + unset( $block_attributes['style']['border']['style'] ); } - // Sides are filtered by skipped serialization only, not by feature support. - $skipped_side_features = array(); - foreach ( array( 'width', 'color', 'style' ) as $feature ) { - if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', $feature ) ) { - $skipped_side_features[] = $feature; - } + if ( ! $has_border_width_support || $skip_width ) { + unset( $block_attributes['style']['border']['width'] ); } + if ( ! $has_border_color_support || $skip_color ) { + unset( $block_attributes['style']['border']['color'], $block_attributes['borderColor'] ); + } + + // Sides are filtered by skipped serialization only, not by feature support. foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { - if ( - ! ( $has_border_color_support || $has_border_width_support ) || - ! isset( $attributes['style']['border'][ $side ] ) || - ! is_array( $attributes['style']['border'][ $side ] ) - ) { - unset( $attributes['style']['border'][ $side ] ); + $has_side = isset( $block_attributes['style']['border'][ $side ] ) && is_array( $block_attributes['style']['border'][ $side ] ); + + if ( ! $has_side || ( ! $has_border_color_support && ! $has_border_width_support ) ) { + unset( $block_attributes['style']['border'][ $side ] ); continue; } - foreach ( $skipped_side_features as $feature ) { - unset( $attributes['style']['border'][ $side ][ $feature ] ); + + if ( $skip_width ) { + unset( $block_attributes['style']['border'][ $side ]['width'] ); + } + + if ( $skip_color ) { + unset( $block_attributes['style']['border'][ $side ]['color'] ); + } + + if ( $skip_style ) { + unset( $block_attributes['style']['border'][ $side ]['style'] ); } } - return gutenberg_get_border_classes_and_styles( $attributes ); + return gutenberg_get_border_classes_and_styles( $block_attributes ); } /** From 74c68eaa88f5a1e87d00f4b19ae54561148a33c4 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:30:16 +0800 Subject: [PATCH 06/15] 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 ff50ba0379849a..2a4060e24f7e52 100644 --- a/phpunit/blocks/render-block-post-navigation-link-test.php +++ b/phpunit/blocks/render-block-post-navigation-link-test.php @@ -143,7 +143,7 @@ public function test_rendered_link_support_styles_full_markup() { $this->assertSame( array( 'class' => 'post-navigation-link-previous has-border-color has-accent-2-border-color wp-block-post-navigation-link', - 'style' => 'border-radius:5px;border-style:dashed;border-width:3px;border-top-width:4px;border-top-color:#ff0000;border-top-style:solid;box-shadow:10px 10px 5px #000000;padding-top:20px;margin-top:30px', + 'style' => 'border-radius:5px;border-style:dashed;border-width:3px;border-top-width:4px;border-top-color:#ff0000;border-top-style:solid;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:30px', ), array( 'class' => $processor->get_attribute( 'class' ), From 6fbac2b9ad0671e87278851b3250d9013dbe2c58 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:23 +0800 Subject: [PATCH 07/15] Match the color helper's preset check, trim the tests and rename the style variables An empty, null, false or zero borderColor now falls back to the custom color, as in the color helper and JS. The quirk tests for side rules are dropped, and the block tests keep one exact-output test each. --- lib/block-supports/border.php | 17 ++- phpunit/block-supports/border-test.php | 115 +++--------------- ...render-block-post-navigation-link-test.php | 5 +- 3 files changed, 30 insertions(+), 107 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 3a6cd726d71542..2d0a1f4c62332e 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -53,7 +53,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { $skip_style = wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ); $skip_width = wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ); - // The helper reads only `style.border`, so a non-array value counts as no border styles. + // The unset() calls below fail on a non-array style or border. if ( ! isset( $block_attributes['style']['border'] ) || ! is_array( $block_attributes['style']['border'] ) ) { unset( $block_attributes['style'] ); } @@ -74,7 +74,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { unset( $block_attributes['style']['border']['color'], $block_attributes['borderColor'] ); } - // Sides are filtered by skipped serialization only, not by feature support. + // Side values follow skipped serialization only, as on trunk. foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { $has_side = isset( $block_attributes['style']['border'][ $side ] ) && is_array( $block_attributes['style']['border'][ $side ] ); @@ -132,8 +132,17 @@ function gutenberg_get_border_classes_and_styles( $block_attributes ) { $border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width']; } - $preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null; - $border_styles['color'] = $preset_border_color ? $preset_border_color : ( $border['color'] ?? null ); + $preset_slug = $block_attributes['borderColor'] ?? null; + if ( true === $preset_slug ) { + $preset_slug = 'true'; + } + + // Mirrors JS truthiness, so '0' is a slug. Arrays cannot form a class name. + $has_preset = is_string( $preset_slug ) + ? '' !== $preset_slug + : ( is_int( $preset_slug ) || is_float( $preset_slug ) ) && 0.0 !== (float) $preset_slug; + + $border_styles['color'] = $has_preset ? "var:preset|color|{$preset_slug}" : ( $border['color'] ?? null ); foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { if ( ! isset( $border[ $side ] ) || ! is_array( $border[ $side ] ) ) { diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index 7e4ed686d715bc..d5ced859d730b0 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -481,62 +481,6 @@ public function test_split_borders_with_named_colors() { $this->assertSame( $expected, $actual ); } - public function test_split_borders_with_color_support_only_keeps_side_style() { - $block_type = self::register_bordered_block_with_support( - 'test/split-borders-with-color-support-only', - array( - '__experimentalBorder' => array( - 'color' => true, - ), - ) - ); - $block_attrs = array( - 'style' => array( - 'border' => array( - 'style' => 'solid', - 'top' => array( - 'color' => '#72aee6', - 'style' => 'dashed', - ), - ), - ), - ); - $actual = gutenberg_apply_border_support( $block_type, $block_attrs ); - $expected = array( - 'style' => 'border-top-color:#72aee6;border-top-style:dashed;', - ); - - $this->assertSame( $expected, $actual ); - } - - public function test_split_borders_with_width_support_only_keeps_side_color() { - $block_type = self::register_bordered_block_with_support( - 'test/split-borders-with-width-support-only', - array( - '__experimentalBorder' => array( - 'width' => true, - ), - ) - ); - $block_attrs = array( - 'borderColor' => 'red', - 'style' => array( - 'border' => array( - 'top' => array( - 'color' => '#72aee6', - 'width' => '2px', - ), - ), - ), - ); - $actual = gutenberg_apply_border_support( $block_type, $block_attrs ); - $expected = array( - 'style' => 'border-top-width:2px;border-top-color:#72aee6;', - ); - - $this->assertSame( $expected, $actual ); - } - public function test_split_borders_without_color_or_width_support_are_dropped() { $block_type = self::register_bordered_block_with_support( 'test/split-borders-without-color-or-width-support', @@ -609,7 +553,7 @@ public function test_get_border_classes_and_styles( $block_attributes, $expected */ public function data_get_border_classes_and_styles() { return array( - 'custom' => array( + 'custom' => array( 'block_attributes' => array( 'style' => array( 'border' => array( @@ -630,7 +574,7 @@ public function data_get_border_classes_and_styles() { 'style' => 'border-color:#ff0000;border-radius:10px;border-style:solid;border-width:2px;border-top-width:3px;border-top-color:#00ff00;border-top-style:dashed;', ), ), - 'preset wins over custom' => array( + 'preset wins over custom' => array( 'block_attributes' => array( 'borderColor' => 'red', 'style' => array( @@ -643,69 +587,38 @@ public function data_get_border_classes_and_styles() { 'class' => 'has-border-color has-red-border-color', ), ), - 'preset only' => array( + 'empty preset keeps custom' => array( 'block_attributes' => array( - 'borderColor' => 'red', - ), - 'expected' => array( - 'class' => 'has-border-color has-red-border-color', - ), - ), - 'numeric' => array( - 'block_attributes' => array( - 'style' => array( + 'borderColor' => '', + 'style' => array( 'border' => array( - 'radius' => 5, - 'width' => 2, + 'color' => '#ff0000', ), ), ), 'expected' => array( - 'style' => 'border-radius:5px;border-width:2px;', + 'class' => 'has-border-color', + 'style' => 'border-color:#ff0000;', ), ), - 'zero' => array( + 'numeric' => array( 'block_attributes' => array( 'style' => array( 'border' => array( - 'radius' => 0, - 'width' => 0, + 'radius' => 5, + 'width' => 2, ), ), ), 'expected' => array( - 'style' => 'border-radius:0px;border-width:0px;', + 'style' => 'border-radius:5px;border-width:2px;', ), ), - 'empty' => array( + 'empty' => array( 'block_attributes' => array(), 'expected' => array(), ), - 'malformed border' => array( - 'block_attributes' => array( - 'style' => array( - 'border' => 'solid', - ), - ), - 'expected' => array(), - ), - 'malformed side' => array( - 'block_attributes' => array( - 'style' => array( - 'border' => array( - 'top' => '1px solid', - ), - ), - ), - 'expected' => array(), - ), - 'malformed style' => array( - 'block_attributes' => array( - 'style' => 'border:1px solid', - ), - 'expected' => array(), - ), - 'malformed non-array' => array( + 'malformed non-array' => array( 'block_attributes' => 'border', 'expected' => array(), ), diff --git a/phpunit/blocks/render-block-post-navigation-link-test.php b/phpunit/blocks/render-block-post-navigation-link-test.php index 2a4060e24f7e52..3232377eab2476 100644 --- a/phpunit/blocks/render-block-post-navigation-link-test.php +++ b/phpunit/blocks/render-block-post-navigation-link-test.php @@ -137,13 +137,14 @@ public function test_rendered_link_support_styles_full_markup() { 'color' => '#ff0000', 'style' => 'solid', ); + $attributes['style']['background'] = array( 'backgroundImage' => array( 'url' => 'https://example.com/image.jpg' ) ); $processor = new WP_HTML_Tag_Processor( $this->render_block( self::$second_post_id, $attributes ) ); $this->assertTrue( $processor->next_tag( 'div' ) ); $this->assertSame( array( - 'class' => 'post-navigation-link-previous has-border-color has-accent-2-border-color wp-block-post-navigation-link', - 'style' => 'border-radius:5px;border-style:dashed;border-width:3px;border-top-width:4px;border-top-color:#ff0000;border-top-style:solid;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:30px', + 'class' => 'post-navigation-link-previous has-border-color has-accent-2-border-color has-background wp-block-post-navigation-link', + 'style' => 'background-image:url(\'https://example.com/image.jpg\');background-size:cover;border-radius:5px;border-style:dashed;border-width:3px;border-top-width:4px;border-top-color:#ff0000;border-top-style:solid;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:30px', ), array( 'class' => $processor->get_attribute( 'class' ), From 941b547d90a9576ef907638676e6d669f08d76b4 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:10:39 +0800 Subject: [PATCH 08/15] Accept only non-empty string border color preset slugs Theme.json slugs are strings and the editor always coerces them, so the numeric and boolean handling only added code. --- lib/block-supports/border.php | 14 +++----------- phpunit/block-supports/border-test.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 2d0a1f4c62332e..c27c228d095d9f 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -132,17 +132,9 @@ function gutenberg_get_border_classes_and_styles( $block_attributes ) { $border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width']; } - $preset_slug = $block_attributes['borderColor'] ?? null; - if ( true === $preset_slug ) { - $preset_slug = 'true'; - } - - // Mirrors JS truthiness, so '0' is a slug. Arrays cannot form a class name. - $has_preset = is_string( $preset_slug ) - ? '' !== $preset_slug - : ( is_int( $preset_slug ) || is_float( $preset_slug ) ) && 0.0 !== (float) $preset_slug; - - $border_styles['color'] = $has_preset ? "var:preset|color|{$preset_slug}" : ( $border['color'] ?? null ); + // Preset slugs are strings in theme.json and the editor. + $preset_slug = $block_attributes['borderColor'] ?? null; + $border_styles['color'] = is_string( $preset_slug ) && '' !== $preset_slug ? "var:preset|color|{$preset_slug}" : ( $border['color'] ?? null ); foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { if ( ! isset( $border[ $side ] ) || ! is_array( $border[ $side ] ) ) { diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index d5ced859d730b0..95fe7ade3aa72d 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -601,6 +601,20 @@ public function data_get_border_classes_and_styles() { 'style' => 'border-color:#ff0000;', ), ), + 'non-string preset' => array( + 'block_attributes' => array( + 'borderColor' => 1, + 'style' => array( + 'border' => array( + 'color' => '#ff0000', + ), + ), + ), + 'expected' => array( + 'class' => 'has-border-color', + 'style' => 'border-color:#ff0000;', + ), + ), 'numeric' => array( 'block_attributes' => array( 'style' => array( From f061201a5cb9a449a90148ace852840331e98e1c Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:18:29 +0800 Subject: [PATCH 09/15] Move the border classes and styles helper to WordPress 7.3 --- backport-changelog/7.2/14094.md | 7 ------- lib/block-supports/border.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/border.php b/lib/block-supports/border.php index c27c228d095d9f..3646d44ed0df3c 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -104,7 +104,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { * `getBorderClassesAndStyles()`. 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 171e1b715bd2a98627291419ef88c81f60a4029e Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 2 Nov 2026 10:58:47 +0800 Subject: [PATCH 10/15] Add the missing covers tag to the border helper test --- phpunit/block-supports/border-test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpunit/block-supports/border-test.php b/phpunit/block-supports/border-test.php index 95fe7ade3aa72d..cc86e8940a0d0c 100644 --- a/phpunit/block-supports/border-test.php +++ b/phpunit/block-supports/border-test.php @@ -537,6 +537,8 @@ public function test_non_array_border_and_sides_are_ignored() { } /** + * @covers ::gutenberg_get_border_classes_and_styles + * * @dataProvider data_get_border_classes_and_styles * * @param mixed $block_attributes Block attributes. From 432886efbd05df4e91de940962b513e3a7b33435 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 2 Nov 2026 19:59:49 +0800 Subject: [PATCH 11/15] PHPStan: Baseline the border 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 de4f2e3b8f1762..4c326d56d9b15f 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_border_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 @@ -120,6 +126,12 @@ parameters: count: 1 path: ../../packages/block-library/src/gallery/index.php + - + message: '#^Function wp_get_border_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,18 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php + - + message: '#^Function wp_get_border_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/post-featured-image/index.php + + - + message: '#^Function wp_get_border_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 3b7b93f2fa82908cc3597098dc75e24ad6d9d381 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 4 Nov 2026 00:05:51 -0700 Subject: [PATCH 12/15] PHPStan: Generate the WordPress stubs from the core backport The block library calls wp_get_border_classes_and_styles(), which the build prefixes to gutenberg_get_border_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 4c326d56d9b15f..de4f2e3b8f1762 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_border_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 @@ -126,12 +120,6 @@ parameters: count: 1 path: ../../packages/block-library/src/gallery/index.php - - - message: '#^Function wp_get_border_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,18 +186,6 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php - - - message: '#^Function wp_get_border_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/post-featured-image/index.php - - - - message: '#^Function wp_get_border_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 284cd72827a4c1363220393339bfc59211c00652 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:26:01 +0800 Subject: [PATCH 13/15] Revert the WordPress stubs pin to Core PR 14094 This reverts commit f919ae509b4, which was 2d4be1a5281 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 de4f2e3b8f1762..4c326d56d9b15f 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_border_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 @@ -120,6 +126,12 @@ parameters: count: 1 path: ../../packages/block-library/src/gallery/index.php + - + message: '#^Function wp_get_border_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,18 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php + - + message: '#^Function wp_get_border_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/post-featured-image/index.php + + - + message: '#^Function wp_get_border_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 51d506eb229dd6eb20dd38ccecb0643c426c3a0f Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:26:20 +0800 Subject: [PATCH 14/15] PHPStan: Ignore the missing wp_get_border_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 cb73cab91d85b5..9114e6ce8309ab 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -50,6 +50,12 @@ parameters: message: '#^Function wp_get_background_classes_and_styles not found\.$#' identifier: function.notFound + # wp_get_border_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_border_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 4c326d56d9b15f..de4f2e3b8f1762 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_border_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 @@ -126,12 +120,6 @@ parameters: count: 1 path: ../../packages/block-library/src/gallery/index.php - - - message: '#^Function wp_get_border_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,18 +186,6 @@ parameters: count: 1 path: ../../packages/block-library/src/playlist/index.php - - - message: '#^Function wp_get_border_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/post-featured-image/index.php - - - - message: '#^Function wp_get_border_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 f13d079f1dc7e52a0a9b879dfd3fdaafedfb63f4 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:17:20 +0800 Subject: [PATCH 15/15] Expect trunk's background class order 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 3232377eab2476..a7a394e18a6702 100644 --- a/phpunit/blocks/render-block-post-navigation-link-test.php +++ b/phpunit/blocks/render-block-post-navigation-link-test.php @@ -143,7 +143,7 @@ public function test_rendered_link_support_styles_full_markup() { $this->assertTrue( $processor->next_tag( 'div' ) ); $this->assertSame( array( - 'class' => 'post-navigation-link-previous has-border-color has-accent-2-border-color has-background wp-block-post-navigation-link', + 'class' => 'post-navigation-link-previous has-background has-border-color has-accent-2-border-color wp-block-post-navigation-link', 'style' => 'background-image:url(\'https://example.com/image.jpg\');background-size:cover;border-radius:5px;border-style:dashed;border-width:3px;border-top-width:4px;border-top-color:#ff0000;border-top-style:solid;box-shadow:10px 10px 5px #000000;min-height:100px;min-width:200px;padding-top:20px;margin-top:30px', ), array(