From 780e2bc436ccdee9221a9ae5e37490989bee57ed Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 24 Jun 2026 16:21:45 -0700 Subject: [PATCH 1/2] Editor: Guard elements hover styles against a missing hover selector. Only render `:hover` element styles for element types that actually define a hover selector. In `wp_render_elements_support_styles()`, only the `link` element type defines a `hover_selector`. If a block's `style.elements` carries a `:hover` object for `button` or `heading`, accessing `$element_config['hover_selector']` reaches for a key that does not exist, emitting an "Undefined array key 'hover_selector'" warning and passing an empty selector to the style engine. Add a `! empty( $element_config['hover_selector'] )` guard so hover processing is skipped for element types without a hover selector, and extend the elements styles test with a `button` `:hover` case that confirms only the base rule is emitted. Backport of Gutenberg PR https://github.com/WordPress/gutenberg/pull/79511. Props aaronrobertshaw. See #65538. --- .../wpRenderElementsSupportStyles.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php b/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php index 5c9fc8af5819d..7500c1d3f6f5e 100644 --- a/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php +++ b/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php @@ -22,6 +22,7 @@ public function tear_down() { * * @ticket 59555 * @ticket 60557 + * @ticket 65538 * * @covers ::wp_render_elements_support_styles * @@ -185,6 +186,21 @@ public function data_elements_block_support_styles() { ), 'expected_styles' => '/^.wp-elements-\d+ .wp-element-button, .wp-elements-\d+ .wp-block-button__link' . $color_css_rules . '$/', ), + 'button hover styles are skipped without a hover selector' => array( + 'color_settings' => array( 'button' => true ), + 'elements_styles' => array( + 'button' => array( + 'color' => $color_styles, + ':hover' => array( 'color' => $color_styles ), + ), + ), + /* + * Only the base button rule should be emitted. The button element + * type has no `hover_selector`, so the `:hover` object must be + * ignored rather than triggering an undefined array key warning. + */ + 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} .wp-element-button, .wp-elements-[a-f0-9]{32} .wp-block-button__link' . $color_css_rules . '$/', + ), 'link element styles are applied' => array( 'color_settings' => array( 'link' => true ), 'elements_styles' => array( From f4605cc9b7ed6bc88e06047d40fbbdc15576667b Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 25 Jun 2026 13:36:34 -0700 Subject: [PATCH 2/2] Correct test regex for recent change to element classname generation --- .../tests/block-supports/wpRenderElementsSupportStyles.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php b/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php index 7500c1d3f6f5e..386d2a0041159 100644 --- a/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php +++ b/tests/phpunit/tests/block-supports/wpRenderElementsSupportStyles.php @@ -194,12 +194,13 @@ public function data_elements_block_support_styles() { ':hover' => array( 'color' => $color_styles ), ), ), + /* * Only the base button rule should be emitted. The button element * type has no `hover_selector`, so the `:hover` object must be * ignored rather than triggering an undefined array key warning. */ - 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} .wp-element-button, .wp-elements-[a-f0-9]{32} .wp-block-button__link' . $color_css_rules . '$/', + 'expected_styles' => '/^.wp-elements-\d+ .wp-element-button, .wp-elements-\d+ .wp-block-button__link' . $color_css_rules . '$/', ), 'link element styles are applied' => array( 'color_settings' => array( 'link' => true ),