Making WordPress.org

Changeset 11760


Ignore:
Timestamp:
04/11/2022 06:26:45 PM (4 years ago)
Author:
ryelle
Message:

Pattern Directory: Sync with git WordPress/pattern-directory@c0d8f6a4a66a66b1c33d51339637e674d5aa90ad

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/includes/inline-styles.php

    r11678 r11760  
    2727function render_layout_support_styles( $block_content, $block ) {
    2828        $block_type     = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
    29         $support_layout = gutenberg_block_has_support( $block_type, array( '__experimentalLayout' ), false );
     29        $support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false );
    3030
    3131        if ( ! $support_layout ) {
     
    4545        }
    4646
    47         $id        = uniqid();
    48         $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
     47        $class_name = wp_unique_id( 'wp-container-' );
     48        $gap_value  = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
    4949        // Skip if gap value contains unsupported characters.
    5050        // Regex for CSS value borrowed from `safecss_filter_attr`, and used here
    5151        // because we only want to match against the value, not the CSS attribute.
    52         $gap_value = preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
    53         $style     = gutenberg_get_layout_style( ".wp-container-$id", $used_layout, $has_block_gap_support, $gap_value );
     52        if ( is_array( $gap_value ) ) {
     53                foreach ( $gap_value as $key => $value ) {
     54                        $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
     55                }
     56        } else {
     57                $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
     58        }
     59
     60        // If a block's block.json skips serialization for spacing or spacing.blockGap,
     61        // don't apply the user-defined value to the styles.
     62        $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
     63        $style                         = wp_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization );
    5464        // This assumes the hook only applies to blocks with a single wrapper.
    5565        // I think this is a reasonable limitation for that particular hook.
    5666        $content = preg_replace(
    5767                '/' . preg_quote( 'class="', '/' ) . '/',
    58                 'class="wp-container-' . $id . ' ',
     68                'class="' . esc_attr( $class_name ) . ' ',
    5969                $block_content,
    6070                1
     
    7888 */
    7989function render_elements_support_styles( $block_content, $block ) {
    80 
    8190        if ( ! $block_content ) {
     91                return $block_content;
     92        }
     93
     94        $block_type                    = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
     95        $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' );
     96
     97        if ( $skip_link_color_serialization ) {
    8298                return $block_content;
    8399        }
     
    89105
    90106        /*
    91         * For now we only care about link color.
    92         * This code in the future when we have a public API
    93         * should take advantage of WP_Theme_JSON_Gutenberg::compute_style_properties
    94         * and work for any element and style.
    95         */
     107         * For now we only care about link color.
     108         * This code in the future when we have a public API
     109         * should take advantage of WP_Theme_JSON::compute_style_properties
     110         * and work for any element and style.
     111         */
    96112        if ( null === $link_color ) {
    97113                return $block_content;
    98114        }
    99115
    100         $class_name = 'wp-elements-' . uniqid();
     116        $class_name = wp_unique_id( 'wp-elements-' );
    101117
    102118        if ( strpos( $link_color, 'var:preset|color|' ) !== false ) {
     
    108124        $link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) );
    109125
    110         $style = "<style>.$class_name a{" . $link_color_declaration . ";}</style>\n";
     126        $style = ".$class_name a{" . $link_color_declaration . ';}';
    111127
    112128        // Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
     
    167183                'colors' => $block['attrs']['style']['color']['duotone'],
    168184        );
    169         $filter_property = gutenberg_get_duotone_filter_property( $filter_preset );
    170         $filter_id       = gutenberg_get_duotone_filter_id( $filter_preset );
    171         $filter_svg      = gutenberg_get_duotone_filter_svg( $filter_preset );
     185        $filter_property = wp_get_duotone_filter_property( $filter_preset );
     186        $filter_id       = wp_get_duotone_filter_id( $filter_preset );
     187        $filter_svg      = wp_get_duotone_filter_svg( $filter_preset );
    172188
    173189        $scope     = '.' . $filter_id;
Note: See TracChangeset for help on using the changeset viewer.