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