From 7eb8ce22f66e7cfb13e6e512848639ebf5e160ff Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 08:16:10 +0800 Subject: [PATCH 01/16] Colour: Add a PHP helper for block support classes and styles --- lib/block-supports/colors.php | 99 +++++++++----- packages/block-library/package.json | 1 + packages/block-library/src/calendar/index.php | 26 ++-- phpunit/block-supports/colors-test.php | 94 ++++++++++++++ phpunit/blocks/render-block-calendar-test.php | 121 ++++++++++++++++++ 5 files changed, 296 insertions(+), 45 deletions(-) create mode 100644 phpunit/blocks/render-block-calendar-test.php diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index 7972383ed65cb5..f45261f7e81ead 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -88,42 +88,41 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { ( isset( $color_support['background'] ) && $color_support['background'] ) || ( is_array( $color_support ) && ! isset( $color_support['background'] ) ); $has_gradients_support = $color_support['gradients'] ?? false; - $color_block_styles = array(); - - // Text colors. - // Check support for text colors. - if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) { - $preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null; - $custom_text_color = $block_attributes['style']['color']['text'] ?? null; - $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color; - } - - // Background colors. - if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) { - $preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null; - $custom_background_color = $block_attributes['style']['color']['background'] ?? null; - $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color; - } - // Gradients. // Suppress color.gradient CSS when background.gradient is supported and // explicitly set. background.php owns CSS generation in that case, and // emitting the background shorthand here would conflict with it. $has_background_gradient_support = block_has_support( $block_type, array( 'background', 'gradient' ), false ); $has_background_gradient_value = ! empty( $block_attributes['style']['background']['gradient'] ); - if ( - $has_gradients_support && - ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) && - ! ( $has_background_gradient_support && $has_background_gradient_value ) - ) { - $preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null; - $custom_gradient_color = $block_attributes['style']['color']['gradient'] ?? null; - $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color; + $allowed_features = array( + 'text' => $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ), + 'background' => $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ), + 'gradient' => $has_gradients_support && + ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) && + ! ( $has_background_gradient_support && $has_background_gradient_value ), + ); + $preset_attributes = array( + 'text' => 'textColor', + 'background' => 'backgroundColor', + 'gradient' => 'gradient', + ); + $color_attributes = array(); + + foreach ( $allowed_features as $feature => $is_allowed ) { + if ( ! $is_allowed ) { + continue; + } + $preset_attribute = $preset_attributes[ $feature ]; + if ( array_key_exists( $preset_attribute, $block_attributes ) ) { + $color_attributes[ $preset_attribute ] = $block_attributes[ $preset_attribute ]; + } + if ( isset( $block_attributes['style']['color'][ $feature ] ) ) { + $color_attributes['style']['color'][ $feature ] = $block_attributes['style']['color'][ $feature ]; + } } - $attributes = array(); - $styles = gutenberg_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) ); + $attributes = gutenberg_get_color_classes_and_styles( $color_attributes ); /* * Mirror of the background support: a color clipped to the text paints the @@ -132,11 +131,53 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { $clips_to_text = 'text' === ( $block_attributes['style']['background']['backgroundClip'] ?? null ) && block_has_support( $block_type, array( 'background', 'backgroundClip' ), false ) && ! wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundClip' ); + $has_gradient = ! empty( $color_attributes['gradient'] ) || ! empty( $color_attributes['style']['color']['gradient'] ); + + if ( $clips_to_text && ! $has_gradient && ! empty( $attributes['class'] ) ) { + $classes = array_diff( explode( ' ', $attributes['class'] ), array( 'has-background' ) ); + if ( empty( $classes ) ) { + unset( $attributes['class'] ); + } else { + $attributes['class'] = implode( ' ', $classes ); + } + } + + return $attributes; +} + +/** + * Generates color CSS classes and inline styles from block attributes. + * + * The PHP counterpart of `getColorClassesAndStyles()` in the block editor. + * Support and serialization checks are left to the caller. + * + * @since 7.2.0 + * + * @param array $block_attributes Block attributes. + * + * @return array Colors CSS classes and inline styles. + */ +function gutenberg_get_color_classes_and_styles( $block_attributes ) { + if ( ! is_array( $block_attributes ) ) { + return array(); + } - if ( $clips_to_text && ! empty( $styles['classnames'] ) && empty( $color_block_styles['gradient'] ) ) { - $styles['classnames'] = implode( ' ', array_diff( explode( ' ', $styles['classnames'] ), array( 'has-background' ) ) ); + $color_block_styles = array(); + $preset_attributes = array( + 'text' => array( 'textColor', 'color' ), + 'background' => array( 'backgroundColor', 'color' ), + 'gradient' => array( 'gradient', 'gradient' ), + ); + + foreach ( $preset_attributes as $feature => list( $preset_attribute, $preset_type ) ) { + $preset_value = array_key_exists( $preset_attribute, $block_attributes ) ? "var:preset|{$preset_type}|{$block_attributes[ $preset_attribute ]}" : null; + $custom_value = $block_attributes['style']['color'][ $feature ] ?? null; + $color_block_styles[ $feature ] = $preset_value ? $preset_value : $custom_value; } + $attributes = array(); + $styles = gutenberg_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) ); + if ( ! empty( $styles['classnames'] ) ) { $attributes['class'] = $styles['classnames']; } diff --git a/packages/block-library/package.json b/packages/block-library/package.json index e6f461b3dcbcf0..3437f7ca704d21 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -69,6 +69,7 @@ "classSuffix": "_Gutenberg", "prefixFunctions": [ "wp_apply_colors_support", + "wp_get_color_classes_and_styles", "wp_enqueue_block_support_styles", "wp_get_typography_font_size_value", "wp_style_engine_get_styles", diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index e3870bb46adb5f..68c239b97a3642 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -43,22 +43,16 @@ function render_block_core_calendar( $attributes ) { } } - $color_block_styles = array(); - - // Text color. - $preset_text_color = array_key_exists( 'textColor', $attributes ) ? "var:preset|color|{$attributes['textColor']}" : null; - $custom_text_color = $attributes['style']['color']['text'] ?? null; - $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color; - - // Background Color. - $preset_background_color = array_key_exists( 'backgroundColor', $attributes ) ? "var:preset|color|{$attributes['backgroundColor']}" : null; - $custom_background_color = $attributes['style']['color']['background'] ?? null; - $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color; - - // Generate color styles and classes. - $styles = wp_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) ); - $inline_styles = empty( $styles['css'] ) ? '' : sprintf( ' style="%s"', esc_attr( $styles['css'] ) ); - $classnames = empty( $styles['classnames'] ) ? '' : ' ' . esc_attr( $styles['classnames'] ); + $color_attributes = array_intersect_key( $attributes, array_flip( array( 'textColor', 'backgroundColor' ) ) ); + foreach ( array( 'text', 'background' ) as $feature ) { + if ( isset( $attributes['style']['color'][ $feature ] ) ) { + $color_attributes['style']['color'][ $feature ] = $attributes['style']['color'][ $feature ]; + } + } + + $styles = wp_get_color_classes_and_styles( $color_attributes ); + $inline_styles = empty( $styles['style'] ) ? '' : sprintf( ' style="%s"', esc_attr( $styles['style'] ) ); + $classnames = empty( $styles['class'] ) ? '' : ' ' . esc_attr( $styles['class'] ); if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { $classnames .= ' has-link-color'; } diff --git a/phpunit/block-supports/colors-test.php b/phpunit/block-supports/colors-test.php index 8a6e9e2748ae04..82e19e2280eef0 100644 --- a/phpunit/block-supports/colors-test.php +++ b/phpunit/block-supports/colors-test.php @@ -374,4 +374,98 @@ public function data_background_color_has_background_with_a_clip() { ), ); } + + /** + * @covers ::gutenberg_get_color_classes_and_styles + * + * @dataProvider data_get_color_classes_and_styles + * + * @param mixed $block_attributes Block attributes. + * @param array $expected Expected classes and styles. + */ + public function test_get_color_classes_and_styles( $block_attributes, $expected ) { + $this->assertSame( $expected, gutenberg_get_color_classes_and_styles( $block_attributes ) ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_get_color_classes_and_styles() { + return array( + 'custom' => array( + 'block_attributes' => array( + 'style' => array( + 'color' => array( + 'text' => '#d92828', + 'background' => '#ffffff', + 'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', + ), + ), + ), + 'expected' => array( + 'class' => 'has-text-color has-background', + 'style' => 'color:#d92828;background-color:#ffffff;background:linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%);', + ), + ), + 'preset' => array( + 'block_attributes' => array( + 'textColor' => 'contrast', + 'backgroundColor' => 'base', + 'gradient' => 'vivid-cyan-blue-to-vivid-purple', + ), + 'expected' => array( + 'class' => 'has-text-color has-contrast-color has-background has-base-background-color has-vivid-cyan-blue-to-vivid-purple-gradient-background', + ), + ), + 'preset wins over custom' => array( + 'block_attributes' => array( + 'textColor' => 'contrast', + 'style' => array( + 'color' => array( + 'text' => '#d92828', + ), + ), + ), + 'expected' => array( + 'class' => 'has-text-color has-contrast-color', + ), + ), + 'numeric' => array( + 'block_attributes' => array( + 'textColor' => 1, + ), + 'expected' => array( + 'class' => 'has-text-color has-1-color', + ), + ), + 'zero' => array( + 'block_attributes' => array( + 'style' => array( + 'color' => array( + 'text' => 0, + ), + ), + ), + 'expected' => array(), + ), + 'empty' => array( + 'block_attributes' => array(), + 'expected' => array(), + ), + 'malformed color' => array( + 'block_attributes' => array( + 'style' => array( + 'color' => '#d92828', + ), + ), + 'expected' => array(), + ), + 'malformed attributes' => array( + 'block_attributes' => 'color', + 'expected' => array(), + ), + ); + } } diff --git a/phpunit/blocks/render-block-calendar-test.php b/phpunit/blocks/render-block-calendar-test.php new file mode 100644 index 00000000000000..b21246adc7f44d --- /dev/null +++ b/phpunit/blocks/render-block-calendar-test.php @@ -0,0 +1,121 @@ +post->create( array( 'post_status' => 'publish' ) ); + } + + /** + * @covers ::gutenberg_render_block_core_calendar + * + * @dataProvider data_color_classes_and_styles + * + * @param array $attributes Block attributes. + * @param string $expected_class Expected table class attribute. + * @param string|null $expected_style Expected table style attribute. + */ + public function test_applies_color_classes_and_styles_to_table( $attributes, $expected_class, $expected_style ) { + $block = new WP_Block( + array( + 'blockName' => 'core/calendar', + 'attrs' => $attributes, + ) + ); + + $processor = new WP_HTML_Tag_Processor( $block->render() ); + + $this->assertTrue( $processor->next_tag( 'table' ) ); + $this->assertSame( $expected_class, $processor->get_attribute( 'class' ) ); + $this->assertSame( $expected_style, $processor->get_attribute( 'style' ) ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_color_classes_and_styles() { + return array( + 'no color' => array( + 'attributes' => array(), + 'expected_class' => 'wp-calendar-table', + 'expected_style' => null, + ), + 'preset colors' => array( + 'attributes' => array( + 'textColor' => 'contrast', + 'backgroundColor' => 'base', + ), + 'expected_class' => 'wp-calendar-table has-text-color has-contrast-color has-background has-base-background-color', + 'expected_style' => null, + ), + 'custom colors' => array( + 'attributes' => array( + 'style' => array( + 'color' => array( + 'text' => '#123456', + 'background' => '#abcdef', + ), + ), + ), + 'expected_class' => 'wp-calendar-table has-text-color has-background', + 'expected_style' => 'color:#123456;background-color:#abcdef;', + ), + 'preset wins over custom' => array( + 'attributes' => array( + 'textColor' => 'contrast', + 'style' => array( + 'color' => array( + 'text' => '#123456', + 'background' => '#abcdef', + ), + ), + ), + 'expected_class' => 'wp-calendar-table has-text-color has-contrast-color has-background', + 'expected_style' => 'background-color:#abcdef;', + ), + 'link color' => array( + 'attributes' => array( + 'textColor' => 'contrast', + 'style' => array( + 'elements' => array( + 'link' => array( + 'color' => array( + 'text' => '#ff0000', + ), + ), + ), + ), + ), + 'expected_class' => 'wp-calendar-table has-text-color has-contrast-color has-link-color', + 'expected_style' => null, + ), + 'gradient is not applied' => array( + 'attributes' => array( + 'gradient' => 'vivid-cyan-blue-to-vivid-purple', + 'style' => array( + 'color' => array( + 'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', + ), + ), + ), + 'expected_class' => 'wp-calendar-table', + 'expected_style' => null, + ), + ); + } +} From 1f4d5e9a23781748f7aed1f3ce62f6ba5325469b Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:11:02 +0800 Subject: [PATCH 02/16] Address review feedback --- lib/block-supports/colors.php | 41 +++---- phpunit/block-supports/colors-test.php | 107 ++++++++++++++++-- phpunit/blocks/render-block-calendar-test.php | 6 +- 3 files changed, 115 insertions(+), 39 deletions(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index f45261f7e81ead..33a467420b90f3 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -89,31 +89,26 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { ( is_array( $color_support ) && ! isset( $color_support['background'] ) ); $has_gradients_support = $color_support['gradients'] ?? false; - // Suppress color.gradient CSS when background.gradient is supported and - // explicitly set. background.php owns CSS generation in that case, and - // emitting the background shorthand here would conflict with it. + // background.php owns the CSS when a background gradient is set, so skip color.gradient. $has_background_gradient_support = block_has_support( $block_type, array( 'background', 'gradient' ), false ); $has_background_gradient_value = ! empty( $block_attributes['style']['background']['gradient'] ); - $allowed_features = array( - 'text' => $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ), - 'background' => $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ), - 'gradient' => $has_gradients_support && - ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) && - ! ( $has_background_gradient_support && $has_background_gradient_value ), + $features = array( + 'text' => array( 'textColor', $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ), + 'background' => array( 'backgroundColor', $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ), + 'gradient' => array( + 'gradient', + $has_gradients_support && + ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) && + ! ( $has_background_gradient_support && $has_background_gradient_value ), + ), ); - $preset_attributes = array( - 'text' => 'textColor', - 'background' => 'backgroundColor', - 'gradient' => 'gradient', - ); - $color_attributes = array(); + $color_attributes = array(); - foreach ( $allowed_features as $feature => $is_allowed ) { + foreach ( $features as $feature => list( $preset_attribute, $is_allowed ) ) { if ( ! $is_allowed ) { continue; } - $preset_attribute = $preset_attributes[ $feature ]; if ( array_key_exists( $preset_attribute, $block_attributes ) ) { $color_attributes[ $preset_attribute ] = $block_attributes[ $preset_attribute ]; } @@ -146,16 +141,14 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { } /** - * Generates color CSS classes and inline styles from block attributes. - * - * The PHP counterpart of `getColorClassesAndStyles()` in the block editor. - * Support and serialization checks are left to the caller. + * Returns color classes and inline styles for block attributes, like the JS + * `getColorClassesAndStyles()`. Does not check block support or skipped + * serialization. * * @since 7.2.0 * * @param array $block_attributes Block attributes. - * - * @return array Colors CSS classes and inline styles. + * @return array Array with `class` and `style` keys, each present only when non-empty. */ function gutenberg_get_color_classes_and_styles( $block_attributes ) { if ( ! is_array( $block_attributes ) ) { @@ -172,7 +165,7 @@ function gutenberg_get_color_classes_and_styles( $block_attributes ) { foreach ( $preset_attributes as $feature => list( $preset_attribute, $preset_type ) ) { $preset_value = array_key_exists( $preset_attribute, $block_attributes ) ? "var:preset|{$preset_type}|{$block_attributes[ $preset_attribute ]}" : null; $custom_value = $block_attributes['style']['color'][ $feature ] ?? null; - $color_block_styles[ $feature ] = $preset_value ? $preset_value : $custom_value; + $color_block_styles[ $feature ] = $preset_value ?? $custom_value; } $attributes = array(); diff --git a/phpunit/block-supports/colors-test.php b/phpunit/block-supports/colors-test.php index 82e19e2280eef0..c9e61c9f02b022 100644 --- a/phpunit/block-supports/colors-test.php +++ b/phpunit/block-supports/colors-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(); } @@ -269,6 +271,74 @@ public function test_color_gradient_emitted_when_background_gradient_is_not_supp $this->assertSame( $expected, $actual ); } + public function test_color_support_true_applies_text_and_background_colors() { + $this->test_block_name = 'test/color-support-true'; + register_block_type( + $this->test_block_name, + array( + 'api_version' => 3, + 'attributes' => array( + 'textColor' => array( + 'type' => 'string', + ), + 'backgroundColor' => array( + 'type' => 'string', + ), + ), + 'supports' => array( + 'color' => true, + ), + ) + ); + + $registry = WP_Block_Type_Registry::get_instance(); + $block_type = $registry->get_registered( $this->test_block_name ); + + $block_atts = array( + 'textColor' => 'contrast', + 'backgroundColor' => 'base', + ); + + $actual = gutenberg_apply_colors_support( $block_type, $block_atts ); + $expected = array( + 'class' => 'has-text-color has-contrast-color has-background has-base-background-color', + ); + + $this->assertSame( $expected, $actual ); + } + + public function test_color_text_support_disabled_skips_text_color() { + $this->test_block_name = 'test/color-text-support-disabled'; + register_block_type( + $this->test_block_name, + array( + 'api_version' => 3, + 'attributes' => array( + 'textColor' => array( + 'type' => 'string', + ), + ), + 'supports' => array( + 'color' => array( + 'text' => false, + ), + ), + ) + ); + + $registry = WP_Block_Type_Registry::get_instance(); + $block_type = $registry->get_registered( $this->test_block_name ); + + $block_atts = array( + 'textColor' => 'contrast', + ); + + $actual = gutenberg_apply_colors_support( $block_type, $block_atts ); + $expected = array(); + + $this->assertSame( $expected, $actual ); + } + /** * Registers a block with color and background clip support. * @@ -394,7 +464,7 @@ public function test_get_color_classes_and_styles( $block_attributes, $expected */ public function data_get_color_classes_and_styles() { return array( - 'custom' => array( + 'custom' => array( 'block_attributes' => array( 'style' => array( 'color' => array( @@ -409,7 +479,7 @@ public function data_get_color_classes_and_styles() { 'style' => 'color:#d92828;background-color:#ffffff;background:linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%);', ), ), - 'preset' => array( + 'preset' => array( 'block_attributes' => array( 'textColor' => 'contrast', 'backgroundColor' => 'base', @@ -419,7 +489,7 @@ public function data_get_color_classes_and_styles() { 'class' => 'has-text-color has-contrast-color has-background has-base-background-color has-vivid-cyan-blue-to-vivid-purple-gradient-background', ), ), - 'preset wins over custom' => array( + 'preset wins over custom' => array( 'block_attributes' => array( 'textColor' => 'contrast', 'style' => array( @@ -432,7 +502,20 @@ public function data_get_color_classes_and_styles() { 'class' => 'has-text-color has-contrast-color', ), ), - 'numeric' => array( + 'null preset wins over custom' => array( + 'block_attributes' => array( + 'textColor' => null, + 'style' => array( + 'color' => array( + 'text' => '#d92828', + ), + ), + ), + 'expected' => array( + 'class' => 'has-text-color', + ), + ), + 'numeric' => array( 'block_attributes' => array( 'textColor' => 1, ), @@ -440,21 +523,23 @@ public function data_get_color_classes_and_styles() { 'class' => 'has-text-color has-1-color', ), ), - 'zero' => array( + 'zero' => array( 'block_attributes' => array( 'style' => array( 'color' => array( - 'text' => 0, + 'text' => '0', ), ), ), - 'expected' => array(), + 'expected' => array( + 'style' => 'color:0;', + ), ), - 'empty' => array( + 'empty' => array( 'block_attributes' => array(), 'expected' => array(), ), - 'malformed color' => array( + 'malformed color' => array( 'block_attributes' => array( 'style' => array( 'color' => '#d92828', @@ -462,7 +547,7 @@ public function data_get_color_classes_and_styles() { ), 'expected' => array(), ), - 'malformed attributes' => array( + 'malformed attributes' => array( 'block_attributes' => 'color', 'expected' => array(), ), diff --git a/phpunit/blocks/render-block-calendar-test.php b/phpunit/blocks/render-block-calendar-test.php index b21246adc7f44d..1693010b5514d5 100644 --- a/phpunit/blocks/render-block-calendar-test.php +++ b/phpunit/blocks/render-block-calendar-test.php @@ -13,10 +13,8 @@ */ class Tests_Blocks_Render_Calendar extends WP_UnitTestCase { - public function set_up() { - parent::set_up(); - - self::factory()->post->create( array( 'post_status' => 'publish' ) ); + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + $factory->post->create( array( 'post_status' => 'publish' ) ); } /** From c741b3232158ed4db243fb0be6e4254c9eec49ab 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/16] 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 827fc435937283ffb8ee524455e0ad011a49c7e7 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 21:14:22 +0800 Subject: [PATCH 04/16] Filter by removing values before calling the helper --- lib/block-supports/colors.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index 33a467420b90f3..8c72be9f0d47c9 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -103,21 +103,20 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { ! ( $has_background_gradient_support && $has_background_gradient_value ), ), ); - $color_attributes = array(); + $attributes = $block_attributes; + $has_color_styles = isset( $attributes['style']['color'] ) && is_array( $attributes['style']['color'] ); foreach ( $features as $feature => list( $preset_attribute, $is_allowed ) ) { - if ( ! $is_allowed ) { + if ( $is_allowed ) { continue; } - if ( array_key_exists( $preset_attribute, $block_attributes ) ) { - $color_attributes[ $preset_attribute ] = $block_attributes[ $preset_attribute ]; - } - if ( isset( $block_attributes['style']['color'][ $feature ] ) ) { - $color_attributes['style']['color'][ $feature ] = $block_attributes['style']['color'][ $feature ]; + unset( $attributes[ $preset_attribute ] ); + if ( $has_color_styles ) { + unset( $attributes['style']['color'][ $feature ] ); } } - $attributes = gutenberg_get_color_classes_and_styles( $color_attributes ); + $classes_and_styles = gutenberg_get_color_classes_and_styles( $attributes ); /* * Mirror of the background support: a color clipped to the text paints the @@ -126,18 +125,18 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { $clips_to_text = 'text' === ( $block_attributes['style']['background']['backgroundClip'] ?? null ) && block_has_support( $block_type, array( 'background', 'backgroundClip' ), false ) && ! wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundClip' ); - $has_gradient = ! empty( $color_attributes['gradient'] ) || ! empty( $color_attributes['style']['color']['gradient'] ); + $has_gradient = ! empty( $attributes['gradient'] ) || ! empty( $attributes['style']['color']['gradient'] ); - if ( $clips_to_text && ! $has_gradient && ! empty( $attributes['class'] ) ) { - $classes = array_diff( explode( ' ', $attributes['class'] ), array( 'has-background' ) ); + if ( $clips_to_text && ! $has_gradient && ! empty( $classes_and_styles['class'] ) ) { + $classes = array_diff( explode( ' ', $classes_and_styles['class'] ), array( 'has-background' ) ); if ( empty( $classes ) ) { - unset( $attributes['class'] ); + unset( $classes_and_styles['class'] ); } else { - $attributes['class'] = implode( ' ', $classes ); + $classes_and_styles['class'] = implode( ' ', $classes ); } } - return $attributes; + return $classes_and_styles; } /** From c74b3e4dd6705e22def590e7304276b11c7c3b1c Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 8 Oct 2026 22:05:55 +0800 Subject: [PATCH 05/16] Use named support and skip variables, and filter the attributes in place --- lib/block-supports/colors.php | 51 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index 8c72be9f0d47c9..6ac19dfd934856 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -88,44 +88,43 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { ( isset( $color_support['background'] ) && $color_support['background'] ) || ( is_array( $color_support ) && ! isset( $color_support['background'] ) ); $has_gradients_support = $color_support['gradients'] ?? false; + $skip_text = wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ); + $skip_background = wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ); + $skip_gradients = wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ); // background.php owns the CSS when a background gradient is set, so skip color.gradient. $has_background_gradient_support = block_has_support( $block_type, array( 'background', 'gradient' ), false ); $has_background_gradient_value = ! empty( $block_attributes['style']['background']['gradient'] ); - - $features = array( - 'text' => array( 'textColor', $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ), - 'background' => array( 'backgroundColor', $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ), - 'gradient' => array( - 'gradient', - $has_gradients_support && - ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) && - ! ( $has_background_gradient_support && $has_background_gradient_value ), - ), - ); - $attributes = $block_attributes; - $has_color_styles = isset( $attributes['style']['color'] ) && is_array( $attributes['style']['color'] ); - - foreach ( $features as $feature => list( $preset_attribute, $is_allowed ) ) { - if ( $is_allowed ) { - continue; - } - unset( $attributes[ $preset_attribute ] ); - if ( $has_color_styles ) { - unset( $attributes['style']['color'][ $feature ] ); - } - } - - $classes_and_styles = gutenberg_get_color_classes_and_styles( $attributes ); + $has_background_gradient = $has_background_gradient_support && $has_background_gradient_value; /* * Mirror of the background support: a color clipped to the text paints the * glyphs, not the box, so only a gradient still adds `has-background`. + * Read before the attributes are filtered for the helper. */ $clips_to_text = 'text' === ( $block_attributes['style']['background']['backgroundClip'] ?? null ) && block_has_support( $block_type, array( 'background', 'backgroundClip' ), false ) && ! wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundClip' ); - $has_gradient = ! empty( $attributes['gradient'] ) || ! empty( $attributes['style']['color']['gradient'] ); + + // The helper reads only `style.color`, so a non-array value counts as no color styles. + if ( ! isset( $block_attributes['style']['color'] ) || ! is_array( $block_attributes['style']['color'] ) ) { + unset( $block_attributes['style'] ); + } + + if ( ! $has_text_colors_support || $skip_text ) { + unset( $block_attributes['textColor'], $block_attributes['style']['color']['text'] ); + } + + if ( ! $has_background_colors_support || $skip_background ) { + unset( $block_attributes['backgroundColor'], $block_attributes['style']['color']['background'] ); + } + + if ( ! $has_gradients_support || $skip_gradients || $has_background_gradient ) { + unset( $block_attributes['gradient'], $block_attributes['style']['color']['gradient'] ); + } + + $classes_and_styles = gutenberg_get_color_classes_and_styles( $block_attributes ); + $has_gradient = ! empty( $block_attributes['gradient'] ) || ! empty( $block_attributes['style']['color']['gradient'] ); if ( $clips_to_text && ! $has_gradient && ! empty( $classes_and_styles['class'] ) ) { $classes = array_diff( explode( ' ', $classes_and_styles['class'] ), array( 'has-background' ) ); From a3b9ae9ca997b7b3f43667edac3ebc01f645cb4d Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:57:12 +0800 Subject: [PATCH 06/16] Fall back to the custom color when a preset attribute is null or empty --- lib/block-supports/colors.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index 6ac19dfd934856..1386c754d898ba 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -161,7 +161,8 @@ function gutenberg_get_color_classes_and_styles( $block_attributes ) { ); foreach ( $preset_attributes as $feature => list( $preset_attribute, $preset_type ) ) { - $preset_value = array_key_exists( $preset_attribute, $block_attributes ) ? "var:preset|{$preset_type}|{$block_attributes[ $preset_attribute ]}" : null; + $preset_slug = $block_attributes[ $preset_attribute ] ?? null; + $preset_value = is_string( $preset_slug ) && '' !== $preset_slug ? "var:preset|{$preset_type}|{$preset_slug}" : null; $custom_value = $block_attributes['style']['color'][ $feature ] ?? null; $color_block_styles[ $feature ] = $preset_value ?? $custom_value; } From a5b5beb5596b805f7971d221764150da5919c2d7 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:57:12 +0800 Subject: [PATCH 07/16] Expect the custom color for a null preset, and drop the style engine cases --- phpunit/block-supports/colors-test.php | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/phpunit/block-supports/colors-test.php b/phpunit/block-supports/colors-test.php index c9e61c9f02b022..396426f9c62c5b 100644 --- a/phpunit/block-supports/colors-test.php +++ b/phpunit/block-supports/colors-test.php @@ -502,7 +502,7 @@ public function data_get_color_classes_and_styles() { 'class' => 'has-text-color has-contrast-color', ), ), - 'null preset wins over custom' => array( + 'null preset uses custom text' => array( 'block_attributes' => array( 'textColor' => null, 'style' => array( @@ -513,26 +513,7 @@ public function data_get_color_classes_and_styles() { ), 'expected' => array( 'class' => 'has-text-color', - ), - ), - 'numeric' => array( - 'block_attributes' => array( - 'textColor' => 1, - ), - 'expected' => array( - 'class' => 'has-text-color has-1-color', - ), - ), - 'zero' => array( - 'block_attributes' => array( - 'style' => array( - 'color' => array( - 'text' => '0', - ), - ), - ), - 'expected' => array( - 'style' => 'color:0;', + 'style' => 'color:#d92828;', ), ), 'empty' => array( From 440a70030127b85b73af0f663ce23d55c54d1265 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:57:13 +0800 Subject: [PATCH 08/16] Drop the no color and preset wins Calendar test cases --- phpunit/blocks/render-block-calendar-test.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/phpunit/blocks/render-block-calendar-test.php b/phpunit/blocks/render-block-calendar-test.php index 1693010b5514d5..045790a91e5fad 100644 --- a/phpunit/blocks/render-block-calendar-test.php +++ b/phpunit/blocks/render-block-calendar-test.php @@ -48,11 +48,6 @@ public function test_applies_color_classes_and_styles_to_table( $attributes, $ex */ public function data_color_classes_and_styles() { return array( - 'no color' => array( - 'attributes' => array(), - 'expected_class' => 'wp-calendar-table', - 'expected_style' => null, - ), 'preset colors' => array( 'attributes' => array( 'textColor' => 'contrast', @@ -73,19 +68,6 @@ public function data_color_classes_and_styles() { 'expected_class' => 'wp-calendar-table has-text-color has-background', 'expected_style' => 'color:#123456;background-color:#abcdef;', ), - 'preset wins over custom' => array( - 'attributes' => array( - 'textColor' => 'contrast', - 'style' => array( - 'color' => array( - 'text' => '#123456', - 'background' => '#abcdef', - ), - ), - ), - 'expected_class' => 'wp-calendar-table has-text-color has-contrast-color has-background', - 'expected_style' => 'background-color:#abcdef;', - ), 'link color' => array( 'attributes' => array( 'textColor' => 'contrast', From 295b8de6b524b448792f386b01591660c9813232 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:57:13 +0800 Subject: [PATCH 09/16] Explain why Calendar filters its color attributes --- packages/block-library/src/calendar/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 68c239b97a3642..2ca0b013529853 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -43,6 +43,7 @@ function render_block_core_calendar( $attributes ) { } } + // Calendar applies only text and background colors, not gradients. $color_attributes = array_intersect_key( $attributes, array_flip( array( 'textColor', 'backgroundColor' ) ) ); foreach ( array( 'text', 'background' ) as $feature ) { if ( isset( $attributes['style']['color'][ $feature ] ) ) { From 1df222f42995f9ca8ac5c989076bc16d35d3fe97 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:08:50 +0800 Subject: [PATCH 10/16] Match JS truthiness for color preset attributes --- lib/block-supports/colors.php | 13 +++++++++++-- phpunit/block-supports/colors-test.php | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index 1386c754d898ba..e80e71f7233850 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -161,8 +161,17 @@ function gutenberg_get_color_classes_and_styles( $block_attributes ) { ); foreach ( $preset_attributes as $feature => list( $preset_attribute, $preset_type ) ) { - $preset_slug = $block_attributes[ $preset_attribute ] ?? null; - $preset_value = is_string( $preset_slug ) && '' !== $preset_slug ? "var:preset|{$preset_type}|{$preset_slug}" : null; + $preset_slug = $block_attributes[ $preset_attribute ] ?? 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; + + $preset_value = $has_preset ? "var:preset|{$preset_type}|{$preset_slug}" : null; $custom_value = $block_attributes['style']['color'][ $feature ] ?? null; $color_block_styles[ $feature ] = $preset_value ?? $custom_value; } diff --git a/phpunit/block-supports/colors-test.php b/phpunit/block-supports/colors-test.php index 396426f9c62c5b..14f7cbbfb86fb0 100644 --- a/phpunit/block-supports/colors-test.php +++ b/phpunit/block-supports/colors-test.php @@ -516,6 +516,14 @@ public function data_get_color_classes_and_styles() { 'style' => 'color:#d92828;', ), ), + 'numeric preset' => array( + 'block_attributes' => array( + 'textColor' => 1, + ), + 'expected' => array( + 'class' => 'has-text-color has-1-color', + ), + ), 'empty' => array( 'block_attributes' => array(), 'expected' => array(), From 977d3360e4439c5f38673f6afa9f6a63fda13ca2 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:04:55 +0800 Subject: [PATCH 11/16] Accept only non-empty string 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/colors.php | 11 ++--------- phpunit/block-supports/colors-test.php | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index e80e71f7233850..29bb069ed332d4 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -162,16 +162,9 @@ function gutenberg_get_color_classes_and_styles( $block_attributes ) { foreach ( $preset_attributes as $feature => list( $preset_attribute, $preset_type ) ) { $preset_slug = $block_attributes[ $preset_attribute ] ?? 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; - $preset_value = $has_preset ? "var:preset|{$preset_type}|{$preset_slug}" : null; + // Preset slugs are strings in theme.json and the editor. + $preset_value = is_string( $preset_slug ) && '' !== $preset_slug ? "var:preset|{$preset_type}|{$preset_slug}" : null; $custom_value = $block_attributes['style']['color'][ $feature ] ?? null; $color_block_styles[ $feature ] = $preset_value ?? $custom_value; } diff --git a/phpunit/block-supports/colors-test.php b/phpunit/block-supports/colors-test.php index 14f7cbbfb86fb0..0cfdb7fe52eb8d 100644 --- a/phpunit/block-supports/colors-test.php +++ b/phpunit/block-supports/colors-test.php @@ -464,7 +464,7 @@ public function test_get_color_classes_and_styles( $block_attributes, $expected */ public function data_get_color_classes_and_styles() { return array( - 'custom' => array( + 'custom' => array( 'block_attributes' => array( 'style' => array( 'color' => array( @@ -479,7 +479,7 @@ public function data_get_color_classes_and_styles() { 'style' => 'color:#d92828;background-color:#ffffff;background:linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%);', ), ), - 'preset' => array( + 'preset' => array( 'block_attributes' => array( 'textColor' => 'contrast', 'backgroundColor' => 'base', @@ -489,7 +489,7 @@ public function data_get_color_classes_and_styles() { 'class' => 'has-text-color has-contrast-color has-background has-base-background-color has-vivid-cyan-blue-to-vivid-purple-gradient-background', ), ), - 'preset wins over custom' => array( + 'preset wins over custom' => array( 'block_attributes' => array( 'textColor' => 'contrast', 'style' => array( @@ -502,7 +502,7 @@ public function data_get_color_classes_and_styles() { 'class' => 'has-text-color has-contrast-color', ), ), - 'null preset uses custom text' => array( + 'null preset uses custom text' => array( 'block_attributes' => array( 'textColor' => null, 'style' => array( @@ -516,19 +516,25 @@ public function data_get_color_classes_and_styles() { 'style' => 'color:#d92828;', ), ), - 'numeric preset' => array( + 'non-string preset uses custom' => array( 'block_attributes' => array( 'textColor' => 1, + 'style' => array( + 'color' => array( + 'text' => '#d92828', + ), + ), ), 'expected' => array( - 'class' => 'has-text-color has-1-color', + 'class' => 'has-text-color', + 'style' => 'color:#d92828;', ), ), - 'empty' => array( + 'empty' => array( 'block_attributes' => array(), 'expected' => array(), ), - 'malformed color' => array( + 'malformed color' => array( 'block_attributes' => array( 'style' => array( 'color' => '#d92828', @@ -536,7 +542,7 @@ public function data_get_color_classes_and_styles() { ), 'expected' => array(), ), - 'malformed attributes' => array( + 'malformed attributes' => array( 'block_attributes' => 'color', 'expected' => array(), ), From 43197fd081393dc609d2b29844edfd3afdb87ae7 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:17:43 +0800 Subject: [PATCH 12/16] Move the color classes and styles helper to WordPress 7.3 --- backport-changelog/{7.2 => 7.3}/14094.md | 0 lib/block-supports/colors.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/colors.php b/lib/block-supports/colors.php index 29bb069ed332d4..7008495b192c8a 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -143,7 +143,7 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { * `getColorClassesAndStyles()`. 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 fe1e7350ecab2dec03a7f537d760ed635707aea9 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 2 Nov 2026 19:34:45 +0800 Subject: [PATCH 13/16] PHPStan: Baseline the colour helper until Core has it --- tools/phpstan/baseline.neon | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index a4d746827c5d0f..dd0e44a5b591a2 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -102,6 +102,12 @@ parameters: count: 1 path: ../../packages/block-library/src/avatar/index.php + - + message: '#^Function wp_get_color_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/calendar/index.php + - message: '#^Variable \$spacing_string might not be defined\.$#' identifier: variable.undefined From 09c0e6860cdfe2be9b2a3afd9a81c4396d0bdd39 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 4 Nov 2026 00:05:10 -0700 Subject: [PATCH 14/16] PHPStan: Generate the WordPress stubs from the core backport The block library calls wp_get_color_classes_and_styles(), which the build prefixes to gutenberg_get_color_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 call was baselined as not found. Generate the stubs from wordpress-develop PR 14094, which backports the helper, and drop the baselined error. 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 | 6 ------ tools/phpstan/wordpress-stubs/composer.json | 9 +++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index dd0e44a5b591a2..a4d746827c5d0f 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -102,12 +102,6 @@ parameters: count: 1 path: ../../packages/block-library/src/avatar/index.php - - - message: '#^Function wp_get_color_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/calendar/index.php - - message: '#^Variable \$spacing_string might not be defined\.$#' identifier: variable.undefined 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 99f3a1ef33da58ee6e1e5e55119664769a10ca14 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:17:13 +0800 Subject: [PATCH 15/16] Revert the WordPress stubs pin to Core PR 14094 This reverts commit 09c0e6860cd. --- tools/phpstan/baseline.neon | 6 ++++++ tools/phpstan/wordpress-stubs/composer.json | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index a4d746827c5d0f..dd0e44a5b591a2 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -102,6 +102,12 @@ parameters: count: 1 path: ../../packages/block-library/src/avatar/index.php + - + message: '#^Function wp_get_color_classes_and_styles not found\.$#' + identifier: function.notFound + count: 1 + path: ../../packages/block-library/src/calendar/index.php + - message: '#^Variable \$spacing_string might not be defined\.$#' identifier: variable.undefined 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 8130a1dd4575112ed0c931d371b7f116e42ee812 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:17:31 +0800 Subject: [PATCH 16/16] PHPStan: Ignore the missing wp_get_color_classes_and_styles() function until the stubs include it --- phpstan.neon.dist | 5 +++++ tools/phpstan/baseline.neon | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9ca9711515a713..fd161800a4f20f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -26,6 +26,11 @@ parameters: - message: '#^Action callback returns .+ but should not return anything\.$#' identifier: return.void + # wp_get_color_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_color_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 diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index dd0e44a5b591a2..a4d746827c5d0f 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -102,12 +102,6 @@ parameters: count: 1 path: ../../packages/block-library/src/avatar/index.php - - - message: '#^Function wp_get_color_classes_and_styles not found\.$#' - identifier: function.notFound - count: 1 - path: ../../packages/block-library/src/calendar/index.php - - message: '#^Variable \$spacing_string might not be defined\.$#' identifier: variable.undefined