Changeset 49226 for trunk/src/wp-includes/block-supports/colors.php
- Timestamp:
- 10/20/2020 01:33:02 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-supports/colors.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/colors.php
r49135 r49226 8 8 /** 9 9 * Registers the style and colors block attributes for block types that support it. 10 * 11 * @access private 10 12 * 11 13 * @param WP_Block_Type $block_type Block Type. … … 54 56 * This will be applied to the block markup in the front-end. 55 57 * 56 * @ param array $attributes Comprehensive list of attributes to be applied.57 * @param array $block_attributes Block attributes.58 * @access private 59 * 58 60 * @param WP_Block_Type $block_type Block type. 61 * @param array $block_attributes Block attributes. 59 62 * 60 63 * @return array Colors CSS classes and inline styles. 61 64 */ 62 function wp_apply_colors_support( $ attributes, $block_attributes, $block_type) {65 function wp_apply_colors_support( $block_type, $block_attributes ) { 63 66 $color_support = wp_array_get( $block_type->supports, array( '__experimentalColor' ), false ); 64 67 $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'text' ), true ) ); … … 66 69 $has_link_colors_support = wp_array_get( $color_support, array( 'linkColor' ), false ); 67 70 $has_gradients_support = wp_array_get( $color_support, array( 'gradients' ), false ); 71 $classes = array(); 72 $styles = array(); 68 73 69 74 // Text Colors. … … 75 80 // Apply required generic class. 76 81 if ( $has_custom_text_color || $has_named_text_color ) { 77 $ attributes['css_classes'][] = 'has-text-color';82 $classes[] = 'has-text-color'; 78 83 } 79 84 // Apply color class or inline style. 80 85 if ( $has_named_text_color ) { 81 $ attributes['css_classes'][] = sprintf( 'has-%s-color', $block_attributes['textColor'] );86 $classes[] = sprintf( 'has-%s-color', $block_attributes['textColor'] ); 82 87 } elseif ( $has_custom_text_color ) { 83 $ attributes['inline_styles'][] = sprintf( 'color: %s;', $block_attributes['style']['color']['text'] );88 $styles[] = sprintf( 'color: %s;', $block_attributes['style']['color']['text'] ); 84 89 } 85 90 } … … 90 95 // Apply required class and style. 91 96 if ( $has_link_color ) { 92 $ attributes['css_classes'][] = 'has-link-color';97 $classes[] = 'has-link-color'; 93 98 // If link is a named color. 94 99 if ( strpos( $block_attributes['style']['color']['link'], 'var:preset|color|' ) !== false ) { 95 100 // Get the name from the string and add proper styles. 96 $index_to_splice = strrpos( $block_attributes['style']['color']['link'], '|' ) + 1;97 $link_color_name = substr( $block_attributes['style']['color']['link'], $index_to_splice );98 $ attributes['inline_styles'][] = sprintf( '--wp--style--color--link:var(--wp--preset--color--%s);', $link_color_name );101 $index_to_splice = strrpos( $block_attributes['style']['color']['link'], '|' ) + 1; 102 $link_color_name = substr( $block_attributes['style']['color']['link'], $index_to_splice ); 103 $styles[] = sprintf( '--wp--style--color--link: var(--wp--preset--color--%s);', $link_color_name ); 99 104 } else { 100 $ attributes['inline_styles'][] = sprintf( '--wp--style--color--link: %s;', $block_attributes['style']['color']['link'] );105 $styles[] = sprintf( '--wp--style--color--link: %s;', $block_attributes['style']['color']['link'] ); 101 106 } 102 107 } … … 110 115 // Apply required background class. 111 116 if ( $has_custom_background_color || $has_named_background_color ) { 112 $ attributes['css_classes'][] = 'has-background';117 $classes[] = 'has-background'; 113 118 } 114 119 // Apply background color classes or styles. 115 120 if ( $has_named_background_color ) { 116 $ attributes['css_classes'][] = sprintf( 'has-%s-background-color', $block_attributes['backgroundColor'] );121 $classes[] = sprintf( 'has-%s-background-color', $block_attributes['backgroundColor'] ); 117 122 } elseif ( $has_custom_background_color ) { 118 $ attributes['inline_styles'][] = sprintf( 'background-color: %s;', $block_attributes['style']['color']['background'] );123 $styles[] = sprintf( 'background-color: %s;', $block_attributes['style']['color']['background'] ); 119 124 } 120 125 } … … 126 131 127 132 if ( $has_named_gradient || $has_custom_gradient ) { 128 $ attributes['css_classes'][] = 'has-background';133 $classes[] = 'has-background'; 129 134 } 130 135 // Apply required background class. 131 136 if ( $has_named_gradient ) { 132 $ attributes['css_classes'][] = sprintf( 'has-%s-gradient-background', $block_attributes['gradient'] );137 $classes[] = sprintf( 'has-%s-gradient-background', $block_attributes['gradient'] ); 133 138 } elseif ( $has_custom_gradient ) { 134 $ attributes['inline_styles'][] = sprintf( 'background: %s;', $block_attributes['style']['color']['gradient'] );139 $styles[] = sprintf( 'background: %s;', $block_attributes['style']['color']['gradient'] ); 135 140 } 141 } 142 143 $attributes = array(); 144 if ( ! empty( $classes ) ) { 145 $attributes['class'] = implode( ' ', $classes ); 146 } 147 if ( ! empty( $styles ) ) { 148 $attributes['style'] = implode( ' ', $styles ); 136 149 } 137 150 138 151 return $attributes; 139 152 } 153 154 // Register the block support. 155 WP_Block_Supports::get_instance()->register( 156 'colors', 157 array( 158 'register_attribute' => 'wp_register_colors_support', 159 'apply' => 'wp_apply_colors_support', 160 ) 161 );
Note: See TracChangeset
for help on using the changeset viewer.