PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.2
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 +17 -41 23.5.3 → 14.5.2 View file →
@@ -10,28 +10,17 @@
10 10 *
11 11 * @param WP_Block_Type $block_type Block Type.
12 12 */
13 13 function gutenberg_register_colors_support( $block_type ) {
14 - $color_support = false;
15 - if ( $block_type instanceof WP_Block_Type ) {
16 - $color_support = $block_type->supports['color'] ?? false;
17 - }
18 - $has_text_colors_support = true === $color_support ||
19 - ( isset( $color_support['text'] ) && $color_support['text'] ) ||
20 - ( is_array( $color_support ) && ! isset( $color_support['text'] ) );
21 - $has_background_colors_support = true === $color_support ||
22 - ( isset( $color_support['background'] ) && $color_support['background'] ) ||
23 - ( is_array( $color_support ) && ! isset( $color_support['background'] ) );
24 - $has_gradients_support = $color_support['gradients'] ?? false;
25 - $has_link_colors_support = $color_support['link'] ?? false;
26 - $has_button_colors_support = $color_support['button'] ?? false;
27 - $has_heading_colors_support = $color_support['heading'] ?? false;
14 + $color_support = property_exists( $block_type, 'supports' ) ? _wp_array_get( $block_type->supports, array( 'color' ), false ) : false;
15 + $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
16 + $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
17 + $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
18 + $has_link_colors_support = _wp_array_get( $color_support, array( 'link' ), false );
28 19 $has_color_support = $has_text_colors_support ||
29 20 $has_background_colors_support ||
30 21 $has_gradients_support ||
31 - $has_link_colors_support ||
32 - $has_button_colors_support ||
33 - $has_heading_colors_support;
22 + $has_link_colors_support;
34 23
35 24 if ( ! $block_type->attributes ) {
36 25 $block_type->attributes = array();
37 26 }
@@ -71,55 +60,42 @@
71 60 *
72 61 * @return array Colors CSS classes and inline styles.
73 62 */
74 63 function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
75 - $color_support = $block_type->supports['color'] ?? false;
64 + $color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
76 65
77 66 if (
78 67 is_array( $color_support ) &&
79 - wp_should_skip_block_supports_serialization( $block_type, 'color' )
68 + gutenberg_should_skip_block_supports_serialization( $block_type, 'color' )
80 69 ) {
81 70 return array();
82 71 }
83 72
84 - $has_text_colors_support = true === $color_support ||
85 - ( isset( $color_support['text'] ) && $color_support['text'] ) ||
86 - ( is_array( $color_support ) && ! isset( $color_support['text'] ) );
87 - $has_background_colors_support = true === $color_support ||
88 - ( isset( $color_support['background'] ) && $color_support['background'] ) ||
89 - ( is_array( $color_support ) && ! isset( $color_support['background'] ) );
90 - $has_gradients_support = $color_support['gradients'] ?? false;
73 + $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
74 + $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
75 + $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
91 76 $color_block_styles = array();
92 77
93 78 // Text colors.
94 79 // Check support for text colors.
95 - if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) {
80 + if ( $has_text_colors_support && ! gutenberg_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) {
96 81 $preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null;
97 - $custom_text_color = $block_attributes['style']['color']['text'] ?? null;
82 + $custom_text_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'text' ), null );
98 83 $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;
99 84 }
100 85
101 86 // Background colors.
102 - if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) {
87 + if ( $has_background_colors_support && ! gutenberg_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) {
103 88 $preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null;
104 - $custom_background_color = $block_attributes['style']['color']['background'] ?? null;
89 + $custom_background_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'background' ), null );
105 90 $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;
106 91 }
107 92
108 93 // Gradients.
109 - // Suppress color.gradient CSS when background.gradient is supported and
110 - // explicitly set. background.php owns CSS generation in that case, and
111 - // emitting the background shorthand here would conflict with it.
112 - $has_background_gradient_support = block_has_support( $block_type, array( 'background', 'gradient' ), false );
113 - $has_background_gradient_value = ! empty( $block_attributes['style']['background']['gradient'] );
114 94
115 - if (
116 - $has_gradients_support &&
117 - ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) &&
118 - ! ( $has_background_gradient_support && $has_background_gradient_value )
119 - ) {
95 + if ( $has_gradients_support && ! gutenberg_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) ) {
120 96 $preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null;
121 - $custom_gradient_color = $block_attributes['style']['color']['gradient'] ?? null;
97 + $custom_gradient_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'gradient' ), null );
122 98 $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color;
123 99 }
124 100
125 101 $attributes = array();