apply_block_core_search_border_style

函数
apply_block_core_search_border_style ( $attributes, $property, $side, $wrapper_styles, $button_styles, $input_styles )
参数
  • (array) $attributes The block attributes.
    Required:
  • (string) $property Border property to generate rule for e.g. width or color.
    Required:
  • (string) $side Optional side border. The dictates the value retrieved and final CSS property.
    Required:
  • (array) $wrapper_styles Current collection of wrapper styles.
    Required:
  • (array) $button_styles Current collection of button styles.
    Required:
  • (array) $input_styles Current collection of input styles.
    Required:
返回值
  • (void)
定义位置
相关方法
apply_block_core_search_border_stylesrender_block_core_searchblock_core_gallery_renderstyles_for_block_core_searchget_block_core_post_featured_image_border_attributes
引入
-
弃用
-

apply_block_core_search_border_style: 一个过滤钩,允许修改搜索块的边框样式。它用于在WordPress的搜索块上应用自定义样式。

这将为给定的边框属性和侧面(如果提供的话)生成一个CSS规则。

基于搜索块是否被配置为显示里面的按钮,生成的规则被注入到适当的样式集合中,以便以后在该块的标记中应用。

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 ) );
	}
}

常见问题

FAQs
查看更多 >