Make WordPress Core


Ignore:
Timestamp:
10/20/2020 01:33:02 PM (6 years ago)
Author:
youknowriad
Message:

Block Editor: Update the WordPress Packages to the latest version.

This includes the packages that match the Gutenberg 9.2 Release.
It is going to be the last block-editor features update for WordPress 5.6.
It also updates the block-supports code base to the latest APIs.

Props isabel_brison, noisysocks, desrosj.
Fixes #51570.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/colors.php

    r49135 r49226  
    88/**
    99 * Registers the style and colors block attributes for block types that support it.
     10 *
     11 * @access private
    1012 *
    1113 * @param WP_Block_Type $block_type Block Type.
     
    5456 * This will be applied to the block markup in the front-end.
    5557 *
    56  * @param  array         $attributes       Comprehensive list of attributes to be applied.
    57  * @param  array         $block_attributes Block attributes.
     58 * @access private
     59 *
    5860 * @param  WP_Block_Type $block_type       Block type.
     61* @param  array         $block_attributes Block attributes.
    5962 *
    6063 * @return array Colors CSS classes and inline styles.
    6164 */
    62 function wp_apply_colors_support( $attributes, $block_attributes, $block_type ) {
     65function wp_apply_colors_support( $block_type, $block_attributes ) {
    6366        $color_support                 = wp_array_get( $block_type->supports, array( '__experimentalColor' ), false );
    6467        $has_text_colors_support       = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'text' ), true ) );
     
    6669        $has_link_colors_support       = wp_array_get( $color_support, array( 'linkColor' ), false );
    6770        $has_gradients_support         = wp_array_get( $color_support, array( 'gradients' ), false );
     71        $classes                       = array();
     72        $styles                        = array();
    6873
    6974        // Text Colors.
     
    7580                // Apply required generic class.
    7681                if ( $has_custom_text_color || $has_named_text_color ) {
    77                         $attributes['css_classes'][] = 'has-text-color';
     82                        $classes[] = 'has-text-color';
    7883                }
    7984                // Apply color class or inline style.
    8085                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'] );
    8287                } 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'] );
    8489                }
    8590        }
     
    9095                // Apply required class and style.
    9196                if ( $has_link_color ) {
    92                         $attributes['css_classes'][] = 'has-link-color';
     97                        $classes[] = 'has-link-color';
    9398                        // If link is a named color.
    9499                        if ( strpos( $block_attributes['style']['color']['link'], 'var:preset|color|' ) !== false ) {
    95100                                // 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 );
    99104                        } 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'] );
    101106                        }
    102107                }
     
    110115                // Apply required background class.
    111116                if ( $has_custom_background_color || $has_named_background_color ) {
    112                         $attributes['css_classes'][] = 'has-background';
     117                        $classes[] = 'has-background';
    113118                }
    114119                // Apply background color classes or styles.
    115120                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'] );
    117122                } 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'] );
    119124                }
    120125        }
     
    126131
    127132                if ( $has_named_gradient || $has_custom_gradient ) {
    128                         $attributes['css_classes'][] = 'has-background';
     133                        $classes[] = 'has-background';
    129134                }
    130135                // Apply required background class.
    131136                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'] );
    133138                } 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'] );
    135140                }
     141        }
     142
     143        $attributes = array();
     144        if ( ! empty( $classes ) ) {
     145                $attributes['class'] = implode( ' ', $classes );
     146        }
     147        if ( ! empty( $styles ) ) {
     148                $attributes['style'] = implode( ' ', $styles );
    136149        }
    137150
    138151        return $attributes;
    139152}
     153
     154// Register the block support.
     155WP_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.