Skip to content

Commit f571f45

Browse files
Editor: add support for block-level link hover colors.
Adds the ability to set link hover colors for individual blocks from the block inspector color panel. Props @youknowriad, @peterwilsoncc, @kebbet. Fixes #58575. git-svn-id: https://develop.svn.wordpress.org/trunk@56028 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3381afd commit f571f45

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/wp-includes/block-supports/elements.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ function wp_render_elements_support( $block_content, $block ) {
4646
$link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null );
4747
}
4848

49+
$hover_link_color = null;
50+
if ( ! empty( $block['attrs'] ) ) {
51+
$hover_link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', ':hover', 'color', 'text' ), null );
52+
}
53+
4954
/*
50-
* For now we only care about link color.
55+
* For now we only care about link colors.
5156
* This code in the future when we have a public API
5257
* should take advantage of WP_Theme_JSON::compute_style_properties
5358
* and work for any element and style.
5459
*/
55-
if ( null === $link_color ) {
60+
if ( null === $link_color && null === $hover_link_color ) {
5661
return $block_content;
5762
}
5863

@@ -104,6 +109,16 @@ function wp_render_elements_support_styles( $pre_render, $block ) {
104109
)
105110
);
106111

112+
if ( isset( $link_block_styles[':hover'] ) ) {
113+
wp_style_engine_get_styles(
114+
$link_block_styles[':hover'],
115+
array(
116+
'selector' => ".$class_name a:hover",
117+
'context' => 'block-supports',
118+
)
119+
);
120+
}
121+
107122
return null;
108123
}
109124

src/wp-includes/class-wp-theme-json.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ class WP_Theme_JSON {
360360
'duotone' => null,
361361
'gradients' => null,
362362
'link' => null,
363+
'heading' => null,
364+
'button' => null,
365+
'caption' => null,
363366
'palette' => null,
364367
'text' => null,
365368
),
@@ -562,6 +565,9 @@ public static function get_element_class_name( $element ) {
562565
array( 'border', 'style' ),
563566
array( 'border', 'width' ),
564567
array( 'color', 'link' ),
568+
array( 'color', 'heading' ),
569+
array( 'color', 'button' ),
570+
array( 'color', 'caption' ),
565571
array( 'dimensions', 'minHeight' ),
566572
array( 'position', 'sticky' ),
567573
array( 'spacing', 'blockGap' ),

src/wp-includes/theme.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
},
1212
"color": {
1313
"background": true,
14+
"button": true,
15+
"caption": true,
1416
"custom": true,
1517
"customDuotone": true,
1618
"customGradient": true,
@@ -121,6 +123,7 @@
121123
"slug": "midnight"
122124
}
123125
],
126+
"heading": true,
124127
"link": false,
125128
"palette": [
126129
{

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ public function test_get_settings_appearance_true_opts_in() {
269269
'color' => true,
270270
),
271271
'color' => array(
272-
'link' => true,
272+
'link' => true,
273+
'heading' => true,
274+
'button' => true,
275+
'caption' => true,
273276
),
274277
'dimensions' => array(
275278
'minHeight' => true,
@@ -299,7 +302,10 @@ public function test_get_settings_appearance_true_opts_in() {
299302
'color' => true,
300303
),
301304
'color' => array(
302-
'link' => true,
305+
'link' => true,
306+
'heading' => true,
307+
'button' => true,
308+
'caption' => true,
303309
),
304310
'dimensions' => array(
305311
'minHeight' => true,

0 commit comments

Comments
 (0)