PluginProbe
Gutenberg / 10.1.0
Gutenberg v10.1.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | lib/block-supports/colors.php +33 -19 12.6.0 → 10.1.0 View file →
@@ -12,24 +12,19 @@
12 12 */
13 13 function gutenberg_register_colors_support( $block_type ) {
14 14 $color_support = false;
15 15 if ( property_exists( $block_type, 'supports' ) ) {
16 - $color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
16 + $color_support = gutenberg_experimental_get( $block_type->supports, array( 'color' ), false );
17 17 }
18 - $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
19 - $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
20 - $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
21 - $has_link_colors_support = _wp_array_get( $color_support, array( 'link' ), false );
22 - $has_color_support = $has_text_colors_support ||
23 - $has_background_colors_support ||
24 - $has_gradients_support ||
25 - $has_link_colors_support;
18 + $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && gutenberg_experimental_get( $color_support, array( 'text' ), true ) );
19 + $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && gutenberg_experimental_get( $color_support, array( 'background' ), true ) );
20 + $has_gradients_support = gutenberg_experimental_get( $color_support, array( 'gradients' ), false );
26 21
27 22 if ( ! $block_type->attributes ) {
28 23 $block_type->attributes = array();
29 24 }
30 25
31 - if ( $has_color_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
26 + if ( $has_text_colors_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
32 27 $block_type->attributes['style'] = array(
33 28 'type' => 'object',
34 29 );
35 30 }
@@ -63,9 +58,9 @@
63 58 *
64 59 * @return array Colors CSS classes and inline styles.
65 60 */
66 61 function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
67 - $color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
62 + $color_support = gutenberg_experimental_get( $block_type->supports, array( 'color' ), false );
68 63
69 64 if (
70 65 is_array( $color_support ) &&
71 66 array_key_exists( '__experimentalSkipSerialization', $color_support ) &&
@@ -73,15 +68,16 @@
73 68 ) {
74 69 return array();
75 70 }
76 71
77 - $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
78 - $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
79 - $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
72 + $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && gutenberg_experimental_get( $color_support, array( 'text' ), true ) );
73 + $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && gutenberg_experimental_get( $color_support, array( 'background' ), true ) );
74 + $has_link_colors_support = gutenberg_experimental_get( $color_support, array( 'link' ), false );
75 + $has_gradients_support = gutenberg_experimental_get( $color_support, array( 'gradients' ), false );
80 76 $classes = array();
81 77 $styles = array();
82 78
83 - // Text colors.
79 + // Text Colors.
84 80 // Check support for text colors.
85 81 if ( $has_text_colors_support ) {
86 82 $has_named_text_color = array_key_exists( 'textColor', $block_attributes );
87 83 $has_custom_text_color = isset( $block_attributes['style']['color']['text'] );
@@ -91,15 +87,33 @@
91 87 $classes[] = 'has-text-color';
92 88 }
93 89 // Apply color class or inline style.
94 90 if ( $has_named_text_color ) {
95 - $classes[] = sprintf( 'has-%s-color', _wp_to_kebab_case( $block_attributes['textColor'] ) );
91 + $classes[] = sprintf( 'has-%s-color', $block_attributes['textColor'] );
96 92 } elseif ( $has_custom_text_color ) {
97 93 $styles[] = sprintf( 'color: %s;', $block_attributes['style']['color']['text'] );
98 94 }
99 95 }
100 96
101 - // Background colors.
97 + // Link Colors.
98 + if ( $has_link_colors_support ) {
99 + $has_link_color = isset( $block_attributes['style']['color']['link'] );
100 + // Apply required class and style.
101 + if ( $has_link_color ) {
102 + $classes[] = 'has-link-color';
103 + // If link is a named color.
104 + if ( strpos( $block_attributes['style']['color']['link'], 'var:preset|color|' ) !== false ) {
105 + // Get the name from the string and add proper styles.
106 + $index_to_splice = strrpos( $block_attributes['style']['color']['link'], '|' ) + 1;
107 + $link_color_name = substr( $block_attributes['style']['color']['link'], $index_to_splice );
108 + $styles[] = sprintf( '--wp--style--color--link: var(--wp--preset--color--%s);', $link_color_name );
109 + } else {
110 + $styles[] = sprintf( '--wp--style--color--link: %s;', $block_attributes['style']['color']['link'] );
111 + }
112 + }
113 + }
114 +
115 + // Background Colors.
102 116 if ( $has_background_colors_support ) {
103 117 $has_named_background_color = array_key_exists( 'backgroundColor', $block_attributes );
104 118 $has_custom_background_color = isset( $block_attributes['style']['color']['background'] );
105 119
@@ -108,9 +122,9 @@
108 122 $classes[] = 'has-background';
109 123 }
110 124 // Apply background color classes or styles.
111 125 if ( $has_named_background_color ) {
112 - $classes[] = sprintf( 'has-%s-background-color', _wp_to_kebab_case( $block_attributes['backgroundColor'] ) );
126 + $classes[] = sprintf( 'has-%s-background-color', $block_attributes['backgroundColor'] );
113 127 } elseif ( $has_custom_background_color ) {
114 128 $styles[] = sprintf( 'background-color: %s;', $block_attributes['style']['color']['background'] );
115 129 }
116 130 }
@@ -124,9 +138,9 @@
124 138 $classes[] = 'has-background';
125 139 }
126 140 // Apply required background class.
127 141 if ( $has_named_gradient ) {
128 - $classes[] = sprintf( 'has-%s-gradient-background', _wp_to_kebab_case( $block_attributes['gradient'] ) );
142 + $classes[] = sprintf( 'has-%s-gradient-background', $block_attributes['gradient'] );
129 143 } elseif ( $has_custom_gradient ) {
130 144 $styles[] = sprintf( 'background: %s;', $block_attributes['style']['color']['gradient'] );
131 145 }
132 146 }