wp_apply_shadow_support

函数
wp_apply_shadow_support ( $block_type, $block_attributes )
Access
Private
参数
  • (WP_Block_Type) $block_type Block type.
    Required:
  • (array) $block_attributes Block attributes.
    Required:
返回值
  • (array) Shadow CSS classes and inline styles.
定义位置
相关方法
wp_apply_spacing_supportwp_apply_colors_supportwp_apply_border_supportwp_apply_dimensions_supportwp_apply_alignment_support
引入
6.3.0
弃用
-

将阴影特征的 CSS 类和内联样式添加到输入的属性数组中。

这将应用于前端的区块标记。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_apply_shadow_support( $block_type, $block_attributes ) {
$has_shadow_support = block_has_support( $block_type, 'shadow', false );
if ( ! $has_shadow_support ) {
return array();
}
$shadow_block_styles = array();
$preset_shadow = array_key_exists( 'shadow', $block_attributes ) ? "var:preset|shadow|{$block_attributes['shadow']}" : null;
$custom_shadow = isset( $block_attributes['style']['shadow'] ) ? $block_attributes['style']['shadow'] : null;
$shadow_block_styles['shadow'] = $preset_shadow ? $preset_shadow : $custom_shadow;
$attributes = array();
$styles = wp_style_engine_get_styles( $shadow_block_styles );
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
}
return $attributes;
}
function wp_apply_shadow_support( $block_type, $block_attributes ) { $has_shadow_support = block_has_support( $block_type, 'shadow', false ); if ( ! $has_shadow_support ) { return array(); } $shadow_block_styles = array(); $preset_shadow = array_key_exists( 'shadow', $block_attributes ) ? "var:preset|shadow|{$block_attributes['shadow']}" : null; $custom_shadow = isset( $block_attributes['style']['shadow'] ) ? $block_attributes['style']['shadow'] : null; $shadow_block_styles['shadow'] = $preset_shadow ? $preset_shadow : $custom_shadow; $attributes = array(); $styles = wp_style_engine_get_styles( $shadow_block_styles ); if ( ! empty( $styles['css'] ) ) { $attributes['style'] = $styles['css']; } return $attributes; }
function wp_apply_shadow_support( $block_type, $block_attributes ) {
	$has_shadow_support = block_has_support( $block_type, 'shadow', false );

	if ( ! $has_shadow_support ) {
		return array();
	}

	$shadow_block_styles = array();

	$preset_shadow                 = array_key_exists( 'shadow', $block_attributes ) ? "var:preset|shadow|{$block_attributes['shadow']}" : null;
	$custom_shadow                 = isset( $block_attributes['style']['shadow'] ) ? $block_attributes['style']['shadow'] : null;
	$shadow_block_styles['shadow'] = $preset_shadow ? $preset_shadow : $custom_shadow;

	$attributes = array();
	$styles     = wp_style_engine_get_styles( $shadow_block_styles );

	if ( ! empty( $styles['css'] ) ) {
		$attributes['style'] = $styles['css'];
	}

	return $attributes;
}

常见问题

FAQs
查看更多 >