wp_render_elements_support_styles()WP 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.

Эта функция считается внутренней для использования самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

null. Ничего.

Использование

wp_render_elements_support_styles( $pre_render, $block );
$pre_render(строка|null) (обязательный)
The pre-rendered content.
По умолчанию: null
$block(массив) (обязательный)
The block being rendered.

Список изменений

С версии 6.0.0 Введена.
С версии 6.1.0 Implemented the style engine to generate CSS and classnames.

Код wp_render_elements_support_styles() WP 6.1.1

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