wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_render_elements_support_styles › WordPress Function

Since6.0.0
Deprecatedn/a
wp_render_elements_support_styles ( $pre_render, $block )
Access:
  • private
Parameters: (2)
  • (string|null) $pre_render The pre-rendered content. Default null.
    Required: Yes
  • (array) $block The block being rendered.
    Required: Yes
Returns:
  • (null)
Defined at:
Codex:
Change Log:
  • 6.1.0

Renders 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.


Source

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