WP_Theme_JSON::get_block_styles( array $style_nodes, array $setting_nodes )

Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet.


Description

See glossary at https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax

For each section this creates a new ruleset such as:

block-selector { style-property-one: value; }

Additionally, it’ll also create new rulesets as classes for each preset value such as:

.has-value-color {
  color: value;
}

.has-value-background-color {
  background-color: value;
}

.has-value-font-size {
  font-size: value;
}

.has-value-gradient-background {
  background: value;
}

p.has-value-gradient-background {
  background: value;
}

Top ↑

Parameters

$style_nodes

(array) (Required) Nodes with styles.

$setting_nodes

(array) (Required) Nodes with settings.


Top ↑

Return

(string) The new stylesheet.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

		if ( null !== self::$blocks_metadata ) {
			return self::$blocks_metadata;
		}

		self::$blocks_metadata = array();

		$registry = WP_Block_Type_Registry::get_instance();
		$blocks   = $registry->get_all_registered();
		foreach ( $blocks as $block_name => $block_type ) {
			if (
				isset( $block_type->supports['__experimentalSelector'] ) &&
				is_string( $block_type->supports['__experimentalSelector'] )
			) {
				self::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector'];
			} else {
				self::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) );
			}

			if (
				isset( $block_type->supports['color']['__experimentalDuotone'] ) &&
				is_string( $block_type->supports['color']['__experimentalDuotone'] )
			) {
				self::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone'];
			}

			// Assign defaults, then overwrite those that the block sets by itself.

Top ↑

Changelog

Changelog
Version Description
5.8.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.