WP_Theme_JSON::get_preset_classes()protectedWP 5.9.0

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

}

{} It's a method of the class: WP_Theme_JSON{}

No Hooks.

Return

String. The new stylesheet.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_preset_classes( $setting_nodes, $origins );
$setting_nodes(array) (required)
Nodes with settings.
$origins(array) (required)
List of origins to process presets from.

Changelog

Since 5.9.0 Introduced.

Code of WP_Theme_JSON::get_preset_classes() WP 6.0

protected function get_preset_classes( $setting_nodes, $origins ) {
	$preset_rules = '';

	foreach ( $setting_nodes as $metadata ) {
		if ( null === $metadata['selector'] ) {
			continue;
		}

		$selector      = $metadata['selector'];
		$node          = _wp_array_get( $this->theme_json, $metadata['path'], array() );
		$preset_rules .= static::compute_preset_classes( $node, $selector, $origins );
	}

	return $preset_rules;
}