Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: search.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/search` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Dynamically renders the `core/search` block.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.3.0 Using block.json `viewScript` to register script, and update `view_script_handles()` only when needed.
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes The block attributes.
[12] Fix | Delete
*
[13] Fix | Delete
* @return string The search block markup.
[14] Fix | Delete
*/
[15] Fix | Delete
function render_block_core_search( $attributes ) {
[16] Fix | Delete
// Older versions of the Search block defaulted the label and buttonText
[17] Fix | Delete
// attributes to `__( 'Search' )` meaning that many posts contain `<!--
[18] Fix | Delete
// wp:search /-->`. Support these by defaulting an undefined label and
[19] Fix | Delete
// buttonText to `__( 'Search' )`.
[20] Fix | Delete
$attributes = wp_parse_args(
[21] Fix | Delete
$attributes,
[22] Fix | Delete
array(
[23] Fix | Delete
'label' => __( 'Search' ),
[24] Fix | Delete
'buttonText' => __( 'Search' ),
[25] Fix | Delete
)
[26] Fix | Delete
);
[27] Fix | Delete
[28] Fix | Delete
$input_id = wp_unique_id( 'wp-block-search__input-' );
[29] Fix | Delete
$classnames = classnames_for_block_core_search( $attributes );
[30] Fix | Delete
$show_label = ! empty( $attributes['showLabel'] );
[31] Fix | Delete
$use_icon_button = ! empty( $attributes['buttonUseIcon'] );
[32] Fix | Delete
$show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
[33] Fix | Delete
$button_position = $show_button ? $attributes['buttonPosition'] : null;
[34] Fix | Delete
$query_params = ( ! empty( $attributes['query'] ) ) ? $attributes['query'] : array();
[35] Fix | Delete
$button = '';
[36] Fix | Delete
$query_params_markup = '';
[37] Fix | Delete
$inline_styles = styles_for_block_core_search( $attributes );
[38] Fix | Delete
$color_classes = get_color_classes_for_block_core_search( $attributes );
[39] Fix | Delete
$typography_classes = get_typography_classes_for_block_core_search( $attributes );
[40] Fix | Delete
$is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
[41] Fix | Delete
'button-inside' === $attributes['buttonPosition'];
[42] Fix | Delete
// Border color classes need to be applied to the elements that have a border color.
[43] Fix | Delete
$border_color_classes = get_border_color_classes_for_block_core_search( $attributes );
[44] Fix | Delete
// This variable is a constant and its value is always false at this moment.
[45] Fix | Delete
// It is defined this way because some values depend on it, in case it changes in the future.
[46] Fix | Delete
$open_by_default = false;
[47] Fix | Delete
[48] Fix | Delete
$label_inner_html = empty( $attributes['label'] ) ? __( 'Search' ) : wp_kses_post( $attributes['label'] );
[49] Fix | Delete
$label = new WP_HTML_Tag_Processor( sprintf( '<label %1$s>%2$s</label>', $inline_styles['label'], $label_inner_html ) );
[50] Fix | Delete
if ( $label->next_tag() ) {
[51] Fix | Delete
$label->set_attribute( 'for', $input_id );
[52] Fix | Delete
$label->add_class( 'wp-block-search__label' );
[53] Fix | Delete
if ( $show_label && ! empty( $attributes['label'] ) ) {
[54] Fix | Delete
if ( ! empty( $typography_classes ) ) {
[55] Fix | Delete
$label->add_class( $typography_classes );
[56] Fix | Delete
}
[57] Fix | Delete
} else {
[58] Fix | Delete
$label->add_class( 'screen-reader-text' );
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
$input = new WP_HTML_Tag_Processor( sprintf( '<input type="search" name="s" required %s/>', $inline_styles['input'] ) );
[63] Fix | Delete
$input_classes = array( 'wp-block-search__input' );
[64] Fix | Delete
if ( ! $is_button_inside && ! empty( $border_color_classes ) ) {
[65] Fix | Delete
$input_classes[] = $border_color_classes;
[66] Fix | Delete
}
[67] Fix | Delete
if ( ! empty( $typography_classes ) ) {
[68] Fix | Delete
$input_classes[] = $typography_classes;
[69] Fix | Delete
}
[70] Fix | Delete
if ( $input->next_tag() ) {
[71] Fix | Delete
$input->add_class( implode( ' ', $input_classes ) );
[72] Fix | Delete
$input->set_attribute( 'id', $input_id );
[73] Fix | Delete
$input->set_attribute( 'value', get_search_query() );
[74] Fix | Delete
$input->set_attribute( 'placeholder', $attributes['placeholder'] );
[75] Fix | Delete
[76] Fix | Delete
// If it's interactive, enqueue the script module and add the directives.
[77] Fix | Delete
$is_expandable_searchfield = 'button-only' === $button_position;
[78] Fix | Delete
if ( $is_expandable_searchfield ) {
[79] Fix | Delete
wp_enqueue_script_module( '@wordpress/block-library/search/view' );
[80] Fix | Delete
[81] Fix | Delete
$input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' );
[82] Fix | Delete
$input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' );
[83] Fix | Delete
[84] Fix | Delete
// Adding these attributes manually is needed until the Interactivity API
[85] Fix | Delete
// SSR logic is added to core.
[86] Fix | Delete
$input->set_attribute( 'aria-hidden', 'true' );
[87] Fix | Delete
$input->set_attribute( 'tabindex', '-1' );
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( count( $query_params ) > 0 ) {
[92] Fix | Delete
foreach ( $query_params as $param => $value ) {
[93] Fix | Delete
$query_params_markup .= sprintf(
[94] Fix | Delete
'<input type="hidden" name="%s" value="%s" />',
[95] Fix | Delete
esc_attr( $param ),
[96] Fix | Delete
esc_attr( $value )
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
if ( $show_button ) {
[102] Fix | Delete
$button_classes = array( 'wp-block-search__button' );
[103] Fix | Delete
$button_internal_markup = '';
[104] Fix | Delete
if ( ! empty( $color_classes ) ) {
[105] Fix | Delete
$button_classes[] = $color_classes;
[106] Fix | Delete
}
[107] Fix | Delete
if ( ! empty( $typography_classes ) ) {
[108] Fix | Delete
$button_classes[] = $typography_classes;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
if ( ! $is_button_inside && ! empty( $border_color_classes ) ) {
[112] Fix | Delete
$button_classes[] = $border_color_classes;
[113] Fix | Delete
}
[114] Fix | Delete
if ( ! $use_icon_button ) {
[115] Fix | Delete
if ( ! empty( $attributes['buttonText'] ) ) {
[116] Fix | Delete
$button_internal_markup = wp_kses_post( $attributes['buttonText'] );
[117] Fix | Delete
}
[118] Fix | Delete
} else {
[119] Fix | Delete
$button_classes[] = 'has-icon';
[120] Fix | Delete
$button_internal_markup =
[121] Fix | Delete
'<svg class="search-icon" viewBox="0 0 24 24" width="24" height="24">
[122] Fix | Delete
<path d="M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"></path>
[123] Fix | Delete
</svg>';
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
// Include the button element class.
[127] Fix | Delete
$button_classes[] = wp_theme_get_element_class_name( 'button' );
[128] Fix | Delete
$button = new WP_HTML_Tag_Processor( sprintf( '<button type="submit" %s>%s</button>', $inline_styles['button'], $button_internal_markup ) );
[129] Fix | Delete
[130] Fix | Delete
if ( $button->next_tag() ) {
[131] Fix | Delete
$button->add_class( implode( ' ', $button_classes ) );
[132] Fix | Delete
if ( 'button-only' === $attributes['buttonPosition'] ) {
[133] Fix | Delete
$button->set_attribute( 'data-wp-bind--aria-label', 'state.ariaLabel' );
[134] Fix | Delete
$button->set_attribute( 'data-wp-bind--aria-controls', 'state.ariaControls' );
[135] Fix | Delete
$button->set_attribute( 'data-wp-bind--aria-expanded', 'context.isSearchInputVisible' );
[136] Fix | Delete
$button->set_attribute( 'data-wp-bind--type', 'state.type' );
[137] Fix | Delete
$button->set_attribute( 'data-wp-on--click', 'actions.openSearchInput' );
[138] Fix | Delete
[139] Fix | Delete
// Adding these attributes manually is needed until the Interactivity
[140] Fix | Delete
// API SSR logic is added to core.
[141] Fix | Delete
$button->set_attribute( 'aria-label', __( 'Expand search field' ) );
[142] Fix | Delete
$button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id );
[143] Fix | Delete
$button->set_attribute( 'aria-expanded', 'false' );
[144] Fix | Delete
$button->set_attribute( 'type', 'button' );
[145] Fix | Delete
} else {
[146] Fix | Delete
$button->set_attribute( 'aria-label', wp_strip_all_tags( $attributes['buttonText'] ) );
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
$field_markup_classes = array(
[152] Fix | Delete
'wp-block-search__inside-wrapper',
[153] Fix | Delete
);
[154] Fix | Delete
if ( $is_button_inside && ! empty( $border_color_classes ) ) {
[155] Fix | Delete
$field_markup_classes[] = $border_color_classes;
[156] Fix | Delete
}
[157] Fix | Delete
$field_markup = sprintf(
[158] Fix | Delete
'<div class="%s" %s>%s</div>',
[159] Fix | Delete
esc_attr( implode( ' ', $field_markup_classes ) ),
[160] Fix | Delete
$inline_styles['wrapper'],
[161] Fix | Delete
$input . $query_params_markup . $button
[162] Fix | Delete
);
[163] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes(
[164] Fix | Delete
array( 'class' => $classnames )
[165] Fix | Delete
);
[166] Fix | Delete
$form_directives = '';
[167] Fix | Delete
[168] Fix | Delete
// If it's interactive, add the directives.
[169] Fix | Delete
if ( $is_expandable_searchfield ) {
[170] Fix | Delete
$aria_label_expanded = __( 'Submit Search' );
[171] Fix | Delete
$aria_label_collapsed = __( 'Expand search field' );
[172] Fix | Delete
$form_context = wp_interactivity_data_wp_context(
[173] Fix | Delete
array(
[174] Fix | Delete
'isSearchInputVisible' => $open_by_default,
[175] Fix | Delete
'inputId' => $input_id,
[176] Fix | Delete
'ariaLabelExpanded' => $aria_label_expanded,
[177] Fix | Delete
'ariaLabelCollapsed' => $aria_label_collapsed,
[178] Fix | Delete
)
[179] Fix | Delete
);
[180] Fix | Delete
$form_directives = '
[181] Fix | Delete
data-wp-interactive="core/search"
[182] Fix | Delete
' . $form_context . '
[183] Fix | Delete
data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
[184] Fix | Delete
data-wp-on--keydown="actions.handleSearchKeydown"
[185] Fix | Delete
data-wp-on--focusout="actions.handleSearchFocusout"
[186] Fix | Delete
';
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
return sprintf(
[190] Fix | Delete
'<form role="search" method="get" action="%1s" %2s %3s>%4s</form>',
[191] Fix | Delete
esc_url( home_url( '/' ) ),
[192] Fix | Delete
$wrapper_attributes,
[193] Fix | Delete
$form_directives,
[194] Fix | Delete
$label . $field_markup
[195] Fix | Delete
);
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Registers the `core/search` block on the server.
[200] Fix | Delete
*
[201] Fix | Delete
* @since 5.2.0
[202] Fix | Delete
*/
[203] Fix | Delete
function register_block_core_search() {
[204] Fix | Delete
register_block_type_from_metadata(
[205] Fix | Delete
__DIR__ . '/search',
[206] Fix | Delete
array(
[207] Fix | Delete
'render_callback' => 'render_block_core_search',
[208] Fix | Delete
)
[209] Fix | Delete
);
[210] Fix | Delete
}
[211] Fix | Delete
add_action( 'init', 'register_block_core_search' );
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Builds the correct top level classnames for the 'core/search' block.
[215] Fix | Delete
*
[216] Fix | Delete
* @since 5.6.0
[217] Fix | Delete
*
[218] Fix | Delete
* @param array $attributes The block attributes.
[219] Fix | Delete
*
[220] Fix | Delete
* @return string The classnames used in the block.
[221] Fix | Delete
*/
[222] Fix | Delete
function classnames_for_block_core_search( $attributes ) {
[223] Fix | Delete
$classnames = array();
[224] Fix | Delete
[225] Fix | Delete
if ( ! empty( $attributes['buttonPosition'] ) ) {
[226] Fix | Delete
if ( 'button-inside' === $attributes['buttonPosition'] ) {
[227] Fix | Delete
$classnames[] = 'wp-block-search__button-inside';
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
if ( 'button-outside' === $attributes['buttonPosition'] ) {
[231] Fix | Delete
$classnames[] = 'wp-block-search__button-outside';
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
if ( 'no-button' === $attributes['buttonPosition'] ) {
[235] Fix | Delete
$classnames[] = 'wp-block-search__no-button';
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
if ( 'button-only' === $attributes['buttonPosition'] ) {
[239] Fix | Delete
$classnames[] = 'wp-block-search__button-only wp-block-search__searchfield-hidden';
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( isset( $attributes['buttonUseIcon'] ) ) {
[244] Fix | Delete
if ( ! empty( $attributes['buttonPosition'] ) && 'no-button' !== $attributes['buttonPosition'] ) {
[245] Fix | Delete
if ( $attributes['buttonUseIcon'] ) {
[246] Fix | Delete
$classnames[] = 'wp-block-search__icon-button';
[247] Fix | Delete
} else {
[248] Fix | Delete
$classnames[] = 'wp-block-search__text-button';
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
return implode( ' ', $classnames );
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* This generates a CSS rule for the given border property and side if provided.
[258] Fix | Delete
* Based on whether the Search block is configured to display the button inside
[259] Fix | Delete
* or not, the generated rule is injected into the appropriate collection of
[260] Fix | Delete
* styles for later application in the block's markup.
[261] Fix | Delete
*
[262] Fix | Delete
* @since 6.1.0
[263] Fix | Delete
*
[264] Fix | Delete
* @param array $attributes The block attributes.
[265] Fix | Delete
* @param string $property Border property to generate rule for e.g. width or color.
[266] Fix | Delete
* @param string $side Optional side border. The dictates the value retrieved and final CSS property.
[267] Fix | Delete
* @param array $wrapper_styles Current collection of wrapper styles.
[268] Fix | Delete
* @param array $button_styles Current collection of button styles.
[269] Fix | Delete
* @param array $input_styles Current collection of input styles.
[270] Fix | Delete
*/
[271] Fix | Delete
function apply_block_core_search_border_style( $attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles ) {
[272] Fix | Delete
$is_button_inside = isset( $attributes['buttonPosition'] ) && 'button-inside' === $attributes['buttonPosition'];
[273] Fix | Delete
[274] Fix | Delete
$path = array( 'style', 'border', $property );
[275] Fix | Delete
[276] Fix | Delete
if ( $side ) {
[277] Fix | Delete
array_splice( $path, 2, 0, $side );
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
$value = _wp_array_get( $attributes, $path, false );
[281] Fix | Delete
[282] Fix | Delete
if ( empty( $value ) ) {
[283] Fix | Delete
return;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
if ( 'color' === $property && $side ) {
[287] Fix | Delete
$has_color_preset = str_contains( $value, 'var:preset|color|' );
[288] Fix | Delete
if ( $has_color_preset ) {
[289] Fix | Delete
$named_color_value = substr( $value, strrpos( $value, '|' ) + 1 );
[290] Fix | Delete
$value = sprintf( 'var(--wp--preset--color--%s)', $named_color_value );
[291] Fix | Delete
}
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
$property_suffix = $side ? sprintf( '%s-%s', $side, $property ) : $property;
[295] Fix | Delete
[296] Fix | Delete
if ( $is_button_inside ) {
[297] Fix | Delete
$wrapper_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) );
[298] Fix | Delete
} else {
[299] Fix | Delete
$button_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) );
[300] Fix | Delete
$input_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) );
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* This adds CSS rules for a given border property e.g. width or color. It
[306] Fix | Delete
* injects rules into the provided wrapper, button and input style arrays for
[307] Fix | Delete
* uniform "flat" borders or those with individual sides configured.
[308] Fix | Delete
*
[309] Fix | Delete
* @since 6.1.0
[310] Fix | Delete
*
[311] Fix | Delete
* @param array $attributes The block attributes.
[312] Fix | Delete
* @param string $property Border property to generate rule for e.g. width or color.
[313] Fix | Delete
* @param array $wrapper_styles Current collection of wrapper styles.
[314] Fix | Delete
* @param array $button_styles Current collection of button styles.
[315] Fix | Delete
* @param array $input_styles Current collection of input styles.
[316] Fix | Delete
*/
[317] Fix | Delete
function apply_block_core_search_border_styles( $attributes, $property, &$wrapper_styles, &$button_styles, &$input_styles ) {
[318] Fix | Delete
apply_block_core_search_border_style( $attributes, $property, null, $wrapper_styles, $button_styles, $input_styles );
[319] Fix | Delete
apply_block_core_search_border_style( $attributes, $property, 'top', $wrapper_styles, $button_styles, $input_styles );
[320] Fix | Delete
apply_block_core_search_border_style( $attributes, $property, 'right', $wrapper_styles, $button_styles, $input_styles );
[321] Fix | Delete
apply_block_core_search_border_style( $attributes, $property, 'bottom', $wrapper_styles, $button_styles, $input_styles );
[322] Fix | Delete
apply_block_core_search_border_style( $attributes, $property, 'left', $wrapper_styles, $button_styles, $input_styles );
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Builds an array of inline styles for the search block.
[327] Fix | Delete
*
[328] Fix | Delete
* The result will contain one entry for shared styles such as those for the
[329] Fix | Delete
* inner input or button and a second for the inner wrapper should the block
[330] Fix | Delete
* be positioning the button "inside".
[331] Fix | Delete
*
[332] Fix | Delete
* @since 5.8.0
[333] Fix | Delete
*
[334] Fix | Delete
* @param array $attributes The block attributes.
[335] Fix | Delete
*
[336] Fix | Delete
* @return array Style HTML attribute.
[337] Fix | Delete
*/
[338] Fix | Delete
function styles_for_block_core_search( $attributes ) {
[339] Fix | Delete
$wrapper_styles = array();
[340] Fix | Delete
$button_styles = array();
[341] Fix | Delete
$input_styles = array();
[342] Fix | Delete
$label_styles = array();
[343] Fix | Delete
$is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
[344] Fix | Delete
'button-inside' === $attributes['buttonPosition'];
[345] Fix | Delete
$show_label = ( isset( $attributes['showLabel'] ) ) && false !== $attributes['showLabel'];
[346] Fix | Delete
[347] Fix | Delete
// Add width styles.
[348] Fix | Delete
$has_width = ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] );
[349] Fix | Delete
[350] Fix | Delete
if ( $has_width ) {
[351] Fix | Delete
$wrapper_styles[] = sprintf(
[352] Fix | Delete
'width: %d%s;',
[353] Fix | Delete
esc_attr( $attributes['width'] ),
[354] Fix | Delete
esc_attr( $attributes['widthUnit'] )
[355] Fix | Delete
);
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
// Add border width and color styles.
[359] Fix | Delete
apply_block_core_search_border_styles( $attributes, 'width', $wrapper_styles, $button_styles, $input_styles );
[360] Fix | Delete
apply_block_core_search_border_styles( $attributes, 'color', $wrapper_styles, $button_styles, $input_styles );
[361] Fix | Delete
apply_block_core_search_border_styles( $attributes, 'style', $wrapper_styles, $button_styles, $input_styles );
[362] Fix | Delete
[363] Fix | Delete
// Add border radius styles.
[364] Fix | Delete
$has_border_radius = ! empty( $attributes['style']['border']['radius'] );
[365] Fix | Delete
[366] Fix | Delete
if ( $has_border_radius ) {
[367] Fix | Delete
$default_padding = '4px';
[368] Fix | Delete
$border_radius = $attributes['style']['border']['radius'];
[369] Fix | Delete
[370] Fix | Delete
if ( is_array( $border_radius ) ) {
[371] Fix | Delete
// Apply styles for individual corner border radii.
[372] Fix | Delete
foreach ( $border_radius as $key => $value ) {
[373] Fix | Delete
// Get border-radius CSS variable from preset value if provided.
[374] Fix | Delete
if ( is_string( $value ) && str_contains( $value, 'var:preset|border-radius|' ) ) {
[375] Fix | Delete
$index_to_splice = strrpos( $value, '|' ) + 1;
[376] Fix | Delete
$slug = _wp_to_kebab_case( substr( $value, $index_to_splice ) );
[377] Fix | Delete
$value = "var(--wp--preset--border-radius--$slug)";
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
if ( null !== $value ) {
[381] Fix | Delete
// Convert camelCase key to kebab-case.
[382] Fix | Delete
$name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $key ) );
[383] Fix | Delete
[384] Fix | Delete
// Add shared styles for individual border radii for input & button.
[385] Fix | Delete
$border_style = sprintf(
[386] Fix | Delete
'border-%s-radius: %s;',
[387] Fix | Delete
esc_attr( $name ),
[388] Fix | Delete
esc_attr( $value )
[389] Fix | Delete
);
[390] Fix | Delete
$input_styles[] = $border_style;
[391] Fix | Delete
$button_styles[] = $border_style;
[392] Fix | Delete
[393] Fix | Delete
// Add adjusted border radius styles for the wrapper element
[394] Fix | Delete
// if button is positioned inside.
[395] Fix | Delete
if ( $is_button_inside && ( intval( $value ) !== 0 || str_contains( $value, 'var(--wp--preset--border-radius--' ) ) ) {
[396] Fix | Delete
$wrapper_styles[] = sprintf(
[397] Fix | Delete
'border-%s-radius: calc(%s + %s);',
[398] Fix | Delete
esc_attr( $name ),
[399] Fix | Delete
esc_attr( $value ),
[400] Fix | Delete
$default_padding
[401] Fix | Delete
);
[402] Fix | Delete
}
[403] Fix | Delete
}
[404] Fix | Delete
}
[405] Fix | Delete
} else {
[406] Fix | Delete
// Numeric check is for backwards compatibility purposes.
[407] Fix | Delete
$border_radius = is_numeric( $border_radius ) ? $border_radius . 'px' : $border_radius;
[408] Fix | Delete
// Get border-radius CSS variable from preset value if provided.
[409] Fix | Delete
if ( is_string( $border_radius ) && str_contains( $border_radius, 'var:preset|border-radius|' ) ) {
[410] Fix | Delete
$index_to_splice = strrpos( $border_radius, '|' ) + 1;
[411] Fix | Delete
$slug = _wp_to_kebab_case( substr( $border_radius, $index_to_splice ) );
[412] Fix | Delete
$border_radius = "var(--wp--preset--border-radius--$slug)";
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
$border_style = sprintf( 'border-radius: %s;', esc_attr( $border_radius ) );
[416] Fix | Delete
$input_styles[] = $border_style;
[417] Fix | Delete
$button_styles[] = $border_style;
[418] Fix | Delete
[419] Fix | Delete
if ( $is_button_inside && intval( $border_radius ) !== 0 ) {
[420] Fix | Delete
// Adjust wrapper border radii to maintain visual consistency
[421] Fix | Delete
// with inner elements when button is positioned inside.
[422] Fix | Delete
$wrapper_styles[] = sprintf(
[423] Fix | Delete
'border-radius: calc(%s + %s);',
[424] Fix | Delete
esc_attr( $border_radius ),
[425] Fix | Delete
$default_padding
[426] Fix | Delete
);
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
// Add color styles.
[432] Fix | Delete
$has_text_color = ! empty( $attributes['style']['color']['text'] );
[433] Fix | Delete
if ( $has_text_color ) {
[434] Fix | Delete
$button_styles[] = sprintf( 'color: %s;', $attributes['style']['color']['text'] );
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
$has_background_color = ! empty( $attributes['style']['color']['background'] );
[438] Fix | Delete
if ( $has_background_color ) {
[439] Fix | Delete
$button_styles[] = sprintf( 'background-color: %s;', $attributes['style']['color']['background'] );
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
$has_custom_gradient = ! empty( $attributes['style']['color']['gradient'] );
[443] Fix | Delete
if ( $has_custom_gradient ) {
[444] Fix | Delete
$button_styles[] = sprintf( 'background: %s;', $attributes['style']['color']['gradient'] );
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
// Get typography styles to be shared across inner elements.
[448] Fix | Delete
$typography_styles = esc_attr( get_typography_styles_for_block_core_search( $attributes ) );
[449] Fix | Delete
if ( ! empty( $typography_styles ) ) {
[450] Fix | Delete
$label_styles [] = $typography_styles;
[451] Fix | Delete
$button_styles[] = $typography_styles;
[452] Fix | Delete
$input_styles [] = $typography_styles;
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
// Typography text-decoration is only applied to the label and button.
[456] Fix | Delete
if ( ! empty( $attributes['style']['typography']['textDecoration'] ) ) {
[457] Fix | Delete
$text_decoration_value = sprintf( 'text-decoration: %s;', esc_attr( $attributes['style']['typography']['textDecoration'] ) );
[458] Fix | Delete
$button_styles[] = $text_decoration_value;
[459] Fix | Delete
// Input opts out of text decoration.
[460] Fix | Delete
if ( $show_label ) {
[461] Fix | Delete
$label_styles[] = $text_decoration_value;
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
return array(
[466] Fix | Delete
'input' => ! empty( $input_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $input_styles ) ) ) ) : '',
[467] Fix | Delete
'button' => ! empty( $button_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $button_styles ) ) ) ) : '',
[468] Fix | Delete
'wrapper' => ! empty( $wrapper_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $wrapper_styles ) ) ) ) : '',
[469] Fix | Delete
'label' => ! empty( $label_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $label_styles ) ) ) ) : '',
[470] Fix | Delete
);
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Returns typography classnames depending on whether there are named font sizes/families.
[475] Fix | Delete
*
[476] Fix | Delete
* @since 6.1.0
[477] Fix | Delete
*
[478] Fix | Delete
* @param array $attributes The block attributes.
[479] Fix | Delete
*
[480] Fix | Delete
* @return string The typography color classnames to be applied to the block elements.
[481] Fix | Delete
*/
[482] Fix | Delete
function get_typography_classes_for_block_core_search( $attributes ) {
[483] Fix | Delete
$typography_classes = array();
[484] Fix | Delete
$has_named_font_family = ! empty( $attributes['fontFamily'] );
[485] Fix | Delete
$has_named_font_size = ! empty( $attributes['fontSize'] );
[486] Fix | Delete
[487] Fix | Delete
if ( $has_named_font_size ) {
[488] Fix | Delete
$typography_classes[] = sprintf( 'has-%s-font-size', esc_attr( $attributes['fontSize'] ) );
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
if ( $has_named_font_family ) {
[492] Fix | Delete
$typography_classes[] = sprintf( 'has-%s-font-family', esc_attr( $attributes['fontFamily'] ) );
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
return implode( ' ', $typography_classes );
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
/**
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function