Changeset 50761 for trunk/src/wp-includes/blocks/search.php
- Timestamp:
- 04/15/2021 02:41:38 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/search.php
r49226 r50761 37 37 $input_markup = ''; 38 38 $button_markup = ''; 39 $ width_styles = '';39 $inline_styles = styles_for_block_core_search( $attributes ); 40 40 41 41 if ( $show_label ) { … … 57 57 if ( $show_input ) { 58 58 $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 />', 60 60 $input_id, 61 61 esc_attr( get_search_query() ), 62 esc_attr( $attributes['placeholder'] ) 62 esc_attr( $attributes['placeholder'] ), 63 $inline_styles['shared'] 63 64 ); 64 65 } … … 81 82 82 83 $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'], 84 87 $button_internal_markup 85 88 ); 86 89 } 87 90 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 94 91 $field_markup = sprintf( 95 92 '<div class="wp-block-search__inside-wrapper"%s>%s</div>', 96 $ width_styles,93 $inline_styles['wrapper'], 97 94 $input_markup . $button_markup 98 95 ); … … 160 157 return implode( ' ', $classnames ); 161 158 } 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 */ 171 function 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.