Make WordPress Core


Ignore:
Timestamp:
04/15/2021 02:41:38 PM (6 years ago)
Author:
gziolo
Message:

Editor: Update WordPress packages to use with WordPress 5.8

In the response to the discussion during the Dev Chat, I'm doing a first pass to keep WordPress packages up to date in the WordPress 5.8 release cycle.

See ​https://github.com/WordPress/wordpress-develop/pull/1176 for more details.

Props youknowriad, aristath, andraganescu.
See #52991.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/search.php

    r49226 r50761  
    3737        $input_markup    = '';
    3838        $button_markup   = '';
    39         $width_styles    = '';
     39        $inline_styles   = styles_for_block_core_search( $attributes );
    4040
    4141        if ( $show_label ) {
    … …  
    5757        if ( $show_input ) {
    5858                $input_markup = sprintf(
    59                         '<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" required />',
     59                        '<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" %s required />',
    6060                        $input_id,
    6161                        esc_attr( get_search_query() ),
    62                         esc_attr( $attributes['placeholder'] )
     62                        esc_attr( $attributes['placeholder'] ),
     63                        $inline_styles['shared']
    6364                );
    6465        }
    … …  
    8182
    8283                $button_markup = sprintf(
    83                         '<button type="submit"class="wp-block-search__button ' . $button_classes . '">%s</button>',
     84                        '<button type="submit" class="wp-block-search__button %s"%s>%s</button>',
     85                        $button_classes,
     86                        $inline_styles['shared'],
    8487                        $button_internal_markup
    8588                );
    8689        }
    8790
    88         if ( ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] ) ) {
    89                 if ( ! empty( $attributes['buttonPosition'] ) && 'button-only' !== $attributes['buttonPosition'] ) {
    90                         $width_styles = ' style="width: ' . $attributes['width'] . $attributes['widthUnit'] . ';"';
    91                 }
    92         }
    93 
    9491        $field_markup       = sprintf(
    9592                '<div class="wp-block-search__inside-wrapper"%s>%s</div>',
    96                 $width_styles,
     93                $inline_styles['wrapper'],
    9794                $input_markup . $button_markup
    9895        );
    … …  
    160157        return implode( ' ', $classnames );
    161158}
     159
     160/**
     161 * Builds an array of inline styles for the search block.
     162 *
     163 * The result will contain one entry for shared styles such as those for the
     164 * inner input or button and a second for the inner wrapper should the block
     165 * be positioning the button "inside".
     166 *
     167 * @param  array $attributes The block attributes.
     168 *
     169 * @return array Style HTML attribute.
     170 */
     171function styles_for_block_core_search( $attributes ) {
     172        $shared_styles  = array();
     173        $wrapper_styles = array();
     174
     175        // Add width styles.
     176        $has_width   = ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] );
     177        $button_only = ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'];
     178
     179        if ( $has_width && ! $button_only ) {
     180                $wrapper_styles[] = sprintf(
     181                        'width: %d%s;',
     182                        esc_attr( $attributes['width'] ),
     183                        esc_attr( $attributes['widthUnit'] )
     184                );
     185        }
     186
     187        // Add border radius styles.
     188        $has_border_radius = ! empty( $attributes['style']['border']['radius'] );
     189
     190        if ( $has_border_radius ) {
     191                // Shared style for button and input radius values.
     192                $border_radius   = $attributes['style']['border']['radius'];
     193                $shared_styles[] = sprintf( 'border-radius: %spx;', esc_attr( $border_radius ) );
     194
     195                // Apply wrapper border radius if button placed inside.
     196                $button_inside = ! empty( $attributes['buttonPosition'] ) &&
     197                        'button-inside' === $attributes['buttonPosition'];
     198
     199                if ( $button_inside ) {
     200                        // We adjust the border radius value for the outer wrapper element
     201                        // to make it visually consistent with the radius applied to inner
     202                        // elements.
     203                        $default_padding  = 4;
     204                        $adjusted_radius  = $border_radius + $default_padding;
     205                        $wrapper_styles[] = sprintf( 'border-radius: %dpx;', esc_attr( $adjusted_radius ) );
     206                }
     207        }
     208
     209        return array(
     210                'shared'  => ! empty( $shared_styles ) ? sprintf( ' style="%s"', implode( ' ', $shared_styles ) ) : '',
     211                'wrapper' => ! empty( $wrapper_styles ) ? sprintf( ' style="%s"', implode( ' ', $wrapper_styles ) ) : '',
     212        );
     213}
Note: See TracChangeset for help on using the changeset viewer.