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-includes/block-supports/elements.php
    , line 100
引入
6.0.0
弃用

Render the elements stylesheet.

In the case of nested blocks we want the parent element styles to be rendered before their descendants.
This solves the issue of an element (e.g.: link color) being styled in both the parent and a descendant:
we want the descendant style to take priority, and this is done by loading it after, in DOM order.

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