wp_render_elements_support_styles

函式
wp_render_elements_support_styles ( $pre_render, $block )
Access
Private
引數
  • (string|null) $pre_render The pre-rendered content. Default null.
    Required:
  • (array) $block The block being rendered.
    Required:
返回值
  • (null)
定義位置
相關方法
wp_render_elements_supportwp_enqueue_block_support_styleswp_render_layout_support_flagwp_register_alignment_supportwp_render_duotone_support
引入
6.0.0
棄用
-

wp_render_elements_support_styles: 這個函式輸出為一個塊元素新增支援wp-elements類所需的CSS樣式。

渲染元素的樣式表。

在巢狀塊的情況下,我們希望父元素的樣式在其子元素之前被渲染。這就解決了一個元素(例如:連結顏色)在父元素和子元素中都有樣式的問題:我們希望子元素的樣式優先,這可以通過在DOM順序中載入它來實現。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_render_elements_support_styles( $pre_render, $block ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$element_block_styles = isset( $block['attrs']['style']['elements'] ) ? $block['attrs']['style']['elements'] : null;
/*
* For now we only care about link color.
*/
$skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' );
if ( $skip_link_color_serialization ) {
return null;
}
$class_name = wp_get_elements_class_name( $block );
$link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null;
wp_style_engine_get_styles(
$link_block_styles,
array(
'selector' => ".$class_name a",
'context' => 'block-supports',
)
);
return null;
}
function wp_render_elements_support_styles( $pre_render, $block ) { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); $element_block_styles = isset( $block['attrs']['style']['elements'] ) ? $block['attrs']['style']['elements'] : null; /* * For now we only care about link color. */ $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' ); if ( $skip_link_color_serialization ) { return null; } $class_name = wp_get_elements_class_name( $block ); $link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null; wp_style_engine_get_styles( $link_block_styles, array( 'selector' => ".$class_name a", 'context' => 'block-supports', ) ); return null; }
function wp_render_elements_support_styles( $pre_render, $block ) {
	$block_type           = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
	$element_block_styles = isset( $block['attrs']['style']['elements'] ) ? $block['attrs']['style']['elements'] : null;

	/*
	* For now we only care about link color.
	*/
	$skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' );

	if ( $skip_link_color_serialization ) {
		return null;
	}
	$class_name        = wp_get_elements_class_name( $block );
	$link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null;

	wp_style_engine_get_styles(
		$link_block_styles,
		array(
			'selector' => ".$class_name a",
			'context'  => 'block-supports',
		)
	);

	return null;
}

常見問題

FAQs
檢視更多 >