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規則。

基於搜尋塊是否被配置為顯示裡面的按鈕,生成的規則被注入到適當的樣式集合中,以便以後在該塊的標記中應用。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 ) );
}
}
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 ) ); } }
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
檢視更多 >