WP_Theme_JSON::compute_preset_classes( array $settings, string $selector, string[] $origins ): string

In this article

Given a settings array, returns the generated rulesets for the preset classes.

Parameters

$settingsarrayrequired
Settings to process.
$selectorstringrequired
Selector wrapping the classes.
$originsstring[]required
List of origins to process.

Return

string The result of processing the presets.

Source

protected static function to_ruleset( $selector, $declarations ) {
	if ( empty( $declarations ) ) {
		return '';
	}

	$declaration_block = array_reduce(
		$declarations,
		static function ( $carry, $element ) {
			return $carry .= $element['name'] . ': ' . $element['value'] . ';'; },
		''
	);

	return $selector . '{' . $declaration_block . '}';
}

/**
 * Given a settings array, returns the generated rulesets
 * for the preset classes.
 *
 * @since 5.8.0
 * @since 5.9.0 Added the `$origins` parameter.
 *
 * @param array    $settings Settings to process.
 * @param string   $selector Selector wrapping the classes.
 * @param string[] $origins  List of origins to process.
 * @return string The result of processing the presets.
 */
protected static function compute_preset_classes( $settings, $selector, $origins ) {
	if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
		/*
		 * Classes at the global level do not need any CSS prefixed,
		 * and we don't want to increase its specificity.
		 */
		$selector = '';

Changelog

VersionDescription
5.9.0Added the $origins parameter.
5.8.0Introduced.

User Contributed Notes

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