Changeset 54211 for trunk/src/wp-includes/block-supports/colors.php
- Timestamp:
- 09/19/2022 08:12:02 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-supports/colors.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/colors.php
r53076 r54211 11 11 * 12 12 * @since 5.6.0 13 * @since 6.1.0 Improved $color_support assignment optimization. 13 14 * @access private 14 15 * … … 16 17 */ 17 18 function wp_register_colors_support( $block_type ) { 18 $color_support = false; 19 if ( property_exists( $block_type, 'supports' ) ) { 20 $color_support = _wp_array_get( $block_type->supports, array( 'color' ), false ); 21 } 19 $color_support = property_exists( $block_type, 'supports' ) ? _wp_array_get( $block_type->supports, array( 'color' ), false ) : false; 22 20 $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) ); 23 21 $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) ); … … 64 62 * 65 63 * @since 5.6.0 64 * @since 6.1.0 Implemented the style engine to generate CSS and classnames. 66 65 * @access private 67 66 * … … 84 83 $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) ); 85 84 $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false ); 86 $classes = array(); 87 $styles = array(); 85 $color_block_styles = array(); 88 86 89 87 // Text colors. 90 // Check support for text colors.91 88 if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) { 92 $has_named_text_color = array_key_exists( 'textColor', $block_attributes ); 93 $has_custom_text_color = isset( $block_attributes['style']['color']['text'] ); 94 95 // Apply required generic class. 96 if ( $has_custom_text_color || $has_named_text_color ) { 97 $classes[] = 'has-text-color'; 98 } 99 // Apply color class or inline style. 100 if ( $has_named_text_color ) { 101 $classes[] = sprintf( 'has-%s-color', _wp_to_kebab_case( $block_attributes['textColor'] ) ); 102 } elseif ( $has_custom_text_color ) { 103 $styles[] = sprintf( 'color: %s;', $block_attributes['style']['color']['text'] ); 104 } 89 $preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null; 90 $custom_text_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'text' ), null ); 91 $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color; 105 92 } 106 93 107 94 // Background colors. 108 95 if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) { 109 $has_named_background_color = array_key_exists( 'backgroundColor', $block_attributes ); 110 $has_custom_background_color = isset( $block_attributes['style']['color']['background'] ); 111 112 // Apply required background class. 113 if ( $has_custom_background_color || $has_named_background_color ) { 114 $classes[] = 'has-background'; 115 } 116 // Apply background color classes or styles. 117 if ( $has_named_background_color ) { 118 $classes[] = sprintf( 'has-%s-background-color', _wp_to_kebab_case( $block_attributes['backgroundColor'] ) ); 119 } elseif ( $has_custom_background_color ) { 120 $styles[] = sprintf( 'background-color: %s;', $block_attributes['style']['color']['background'] ); 121 } 96 $preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null; 97 $custom_background_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'background' ), null ); 98 $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color; 122 99 } 123 100 124 101 // Gradients. 125 102 if ( $has_gradients_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) ) { 126 $has_named_gradient = array_key_exists( 'gradient', $block_attributes ); 127 $has_custom_gradient = isset( $block_attributes['style']['color']['gradient'] ); 128 129 if ( $has_named_gradient || $has_custom_gradient ) { 130 $classes[] = 'has-background'; 131 } 132 // Apply required background class. 133 if ( $has_named_gradient ) { 134 $classes[] = sprintf( 'has-%s-gradient-background', _wp_to_kebab_case( $block_attributes['gradient'] ) ); 135 } elseif ( $has_custom_gradient ) { 136 $styles[] = sprintf( 'background: %s;', $block_attributes['style']['color']['gradient'] ); 137 } 103 $preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null; 104 $custom_gradient_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'gradient' ), null ); 105 $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color; 138 106 } 139 107 140 108 $attributes = array(); 141 if ( ! empty( $classes ) ) { 142 $attributes['class'] = implode( ' ', $classes ); 109 $styles = wp_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) ); 110 111 if ( ! empty( $styles['classnames'] ) ) { 112 $attributes['class'] = $styles['classnames']; 143 113 } 144 if ( ! empty( $styles ) ) { 145 $attributes['style'] = implode( ' ', $styles ); 114 115 if ( ! empty( $styles['css'] ) ) { 116 $attributes['style'] = $styles['css']; 146 117 } 147 118
Note: See TracChangeset
for help on using the changeset viewer.