Make WordPress Core


Ignore:
Timestamp:
09/19/2022 08:12:02 PM (3 years ago)
Author:
audrasjb
Message:

Editor: Backport block supports (border, color, elements, spacing) from Gutenberg to WP 6.1.

This changeset backports border, color, elements and spacing block supports changes from Gutenberg to WP 6.1.

See tracking issue on Gutenberg repository: gutenberg#43440.

Props ramonopoly, glendaviesnz, bernhard-reiter, audrasjb, costdev.
See #56467.

File:
1 edited

Legend:

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

    r53260 r54211  
    9090 *
    9191 * @since 6.0.0
     92 * @since 6.1.0 Implemented the style engine to generate CSS and classnames.
    9293 * @access private
    9394 *
     
    9899 */
    99100function wp_render_elements_support_styles( $pre_render, $block ) {
    100     $block_type                    = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
     101    $block_type           = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
     102    $element_block_styles = isset( $block['attrs']['style']['elements'] ) ? $block['attrs']['style']['elements'] : null;
     103
     104    /*
     105    * For now we only care about link color.
     106    */
    101107    $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' );
     108
    102109    if ( $skip_link_color_serialization ) {
    103110        return null;
    104111    }
     112    $class_name        = wp_get_elements_class_name( $block );
     113    $link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null;
    105114
    106     $link_color = null;
    107     if ( ! empty( $block['attrs'] ) ) {
    108         $link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null );
    109     }
    110 
    111     /*
    112     * For now we only care about link color.
    113     * This code in the future when we have a public API
    114     * should take advantage of WP_Theme_JSON::compute_style_properties
    115     * and work for any element and style.
    116     */
    117     if ( null === $link_color ) {
    118         return null;
    119     }
    120 
    121     $class_name = wp_get_elements_class_name( $block );
    122 
    123     if ( strpos( $link_color, 'var:preset|color|' ) !== false ) {
    124         // Get the name from the string and add proper styles.
    125         $index_to_splice = strrpos( $link_color, '|' ) + 1;
    126         $link_color_name = substr( $link_color, $index_to_splice );
    127         $link_color      = "var(--wp--preset--color--$link_color_name)";
    128     }
    129     $link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) );
    130 
    131     $style = ".$class_name a{" . $link_color_declaration . ';}';
    132 
    133     wp_enqueue_block_support_styles( $style );
     115    wp_style_engine_get_styles(
     116        $link_block_styles,
     117        array(
     118            'selector' => ".$class_name a",
     119            'context'  => 'block-supports',
     120        )
     121    );
    134122
    135123    return null;
Note: See TracChangeset for help on using the changeset viewer.