WP_Theme_JSON::get_root_layout_rules( string $selector, array $block_metadata ): string

In this article

Outputs the CSS for layout rules on the root.

Parameters

$selectorstringrequired
The root node selector.
$block_metadataarrayrequired
The metadata for the root block.

Return

string The additional root rules CSS.

Source

		if ( ! empty( $ref_value ) && ( is_string( $ref_value ) || is_string( $ref_value_url ) ) ) {
			$value = $ref_value;
		}

		if ( is_array( $ref_value ) && isset( $ref_value['ref'] ) ) {
			$path_string      = json_encode( $path );
			$ref_value_string = json_encode( $ref_value );
			_doing_it_wrong(
				'get_property_value',
				sprintf(
					/* translators: 1: theme.json, 2: Value name, 3: Value path, 4: Another value name. */
					__( 'Your %1$s file uses a dynamic value (%2$s) for the path at %3$s. However, the value at %3$s is also a dynamic value (pointing to %4$s) and pointing to another dynamic value is not supported. Please update %3$s to point directly to %4$s.' ),
					'theme.json',
					$ref_value_string,
					$path_string,
					$ref_value['ref']
				),
				'6.1.0'
			);
		}
	}

	if ( is_array( $value ) ) {
		return $value;
	}

	return $value;
}

/**
 * Builds metadata for the setting nodes, which returns in the form of:
 *
 *     [
 *       [
 *         'path'     => ['path', 'to', 'some', 'node' ],
 *         'selector' => 'CSS selector for some node'
 *       ],
 *       [
 *         'path'     => [ 'path', 'to', 'other', 'node' ],
 *         'selector' => 'CSS selector for other node'
 *       ],
 *     ]
 *
 * @since 5.8.0
 *
 * @param array $theme_json The tree to extract setting nodes from.
 * @param array $selectors  List of selectors per block.
 * @return array An array of setting nodes metadata.
 */
protected static function get_setting_nodes( $theme_json, $selectors = array() ) {
	$nodes = array();
	if ( ! isset( $theme_json['settings'] ) ) {
		return $nodes;
	}

	// Top-level.
	$nodes[] = array(
		'path'     => array( 'settings' ),
		'selector' => static::ROOT_CSS_PROPERTIES_SELECTOR,
	);

	// Calculate paths for blocks.
	if ( ! isset( $theme_json['settings']['blocks'] ) ) {
		return $nodes;
	}

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

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