diff --git a/backport-changelog/7.1/12312.md b/backport-changelog/7.1/12312.md new file mode 100644 index 00000000000000..422bc0d93ddfb4 --- /dev/null +++ b/backport-changelog/7.1/12312.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/12312 + +* https://github.com/WordPress/gutenberg/pull/79511 diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index 2d7ad497afcab1..9198fc8c9c893f 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -193,7 +193,7 @@ function gutenberg_render_elements_support_styles( $parsed_block ) { ) ); - if ( isset( $element_style_object[':hover'] ) ) { + if ( isset( $element_style_object[':hover'], $element_config['hover_selector'] ) ) { gutenberg_style_engine_get_styles( $element_style_object[':hover'], array( diff --git a/phpunit/block-supports/elements-test.php b/phpunit/block-supports/elements-test.php index cb664cd05c5e15..a45842f8fc1a04 100644 --- a/phpunit/block-supports/elements-test.php +++ b/phpunit/block-supports/elements-test.php @@ -326,6 +326,21 @@ public function data_elements_block_support_styles() { ), 'expected_styles' => '/^.wp-elements-(?:[a-f0-9]{32}|[0-9]+) .wp-element-button, .wp-elements-(?:[a-f0-9]{32}|[0-9]+) .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}|[0-9]+) .wp-element-button, .wp-elements-(?:[a-f0-9]{32}|[0-9]+) .wp-block-button__link' . $color_css_rules . '$/', + ), 'link element styles are applied' => array( 'color_settings' => array( 'link' => true ), 'elements_styles' => array(