apply_block_core_search_border_style

The timeline below displays how wordpress function apply_block_core_search_border_style has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * This generates a CSS rule for the given border property and side if provided.
 * Based on whether the Search block is configured to display the button inside
 * or not, the generated rule is injected into the appropriate collection of
 * styles for later application in the block's markup.
 *
 * @param array  $attributes     The block attributes.
 * @param string $property       Border property to generate rule for e.g. width or color.
 * @param string $side           Optional side border. The dictates the value retrieved and final CSS property.
 * @param array  $wrapper_styles Current collection of wrapper styles.
 * @param array  $button_styles  Current collection of button styles.
 * @param array  $input_styles   Current collection of input styles.
 */
function apply_block_core_search_border_style($attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles)
{
    $is_button_inside = isset($attributes['buttonPosition']) && 'button-inside' === $attributes['buttonPosition'];
    $path = array('style', 'border', $property);
    if ($side) {
        array_splice($path, 2, 0, $side);
    }
    $value = _wp_array_get($attributes, $path, false);
    if (empty($value)) {
        return;
    }
    if ('color' === $property && $side) {
        $has_color_preset = str_contains($value, 'var:preset|color|');
        if ($has_color_preset) {
            $named_color_value = substr($value, strrpos($value, '|') + 1);
            $value = sprintf('var(--wp--preset--color--%s)', $named_color_value);
        }
    }
    $property_suffix = $side ? sprintf('%s-%s', $side, $property) : $property;
    if ($is_button_inside) {
        $wrapper_styles[] = sprintf('border-%s: %s;', $property_suffix, esc_attr($value));
    } else {
        $button_styles[] = sprintf('border-%s: %s;', $property_suffix, esc_attr($value));
        $input_styles[] = sprintf('border-%s: %s;', $property_suffix, esc_attr($value));
    }
}

WordPress Version: 6.1

/**
 * This generates a CSS rule for the given border property and side if provided.
 * Based on whether the Search block is configured to display the button inside
 * or not, the generated rule is injected into the appropriate collection of
 * styles for later application in the block's markup.
 *
 * @param array  $attributes     The block attributes.
 * @param string $property       Border property to generate rule for e.g. width or color.
 * @param string $side           Optional side border. The dictates the value retrieved and final CSS property.
 * @param array  $wrapper_styles Current collection of wrapper styles.
 * @param array  $button_styles  Current collection of button styles.
 * @param array  $input_styles   Current collection of input styles.
 *
 * @return void
 */
function apply_block_core_search_border_style($attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles)
{
    $is_button_inside = 'button-inside' === _wp_array_get($attributes, array('buttonPosition'), false);
    $path = array('style', 'border', $property);
    if ($side) {
        array_splice($path, 2, 0, $side);
    }
    $value = _wp_array_get($attributes, $path, false);
    if (empty($value)) {
        return;
    }
    if ('color' === $property && $side) {
        $has_color_preset = str_contains($value, 'var:preset|color|');
        if ($has_color_preset) {
            $named_color_value = substr($value, strrpos($value, '|') + 1);
            $value = sprintf('var(--wp--preset--color--%s)', $named_color_value);
        }
    }
    $property_suffix = $side ? sprintf('%s-%s', $side, $property) : $property;
    if ($is_button_inside) {
        $wrapper_styles[] = sprintf('border-%s: %s;', $property_suffix, esc_attr($value));
    } else {
        $button_styles[] = sprintf('border-%s: %s;', $property_suffix, esc_attr($value));
        $input_styles[] = sprintf('border-%s: %s;', $property_suffix, esc_attr($value));
    }
}