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

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


Parameters

$settings

(array) (Required) Settings to process.

$selector

(string) (Required) Selector wrapping the classes.

$origins

(array) (Required) List of origins to process.


Top ↑

Return

(string) The result of processing the presets.


Top ↑

Source

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

	private static function compute_preset_classes( $settings, $selector, $origins ) {
		if ( self::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 = '';
		}

		$stylesheet = '';
		foreach ( self::PRESETS_METADATA as $preset_metadata ) {
			$slugs = self::get_settings_slugs( $settings, $preset_metadata, $origins );
			foreach ( $preset_metadata['classes'] as $class => $property ) {
				foreach ( $slugs as $slug ) {
					$css_var     = self::replace_slug_in_string( $preset_metadata['css_vars'], $slug );
					$class_name  = self::replace_slug_in_string( $class, $slug );
					$stylesheet .= self::to_ruleset(
						self::append_to_selector( $selector, $class_name ),
						array(
							array(
								'name'  => $property,
								'value' => 'var(' . $css_var . ') !important',
							),
						)
					);
				}
			}
		}

		return $stylesheet;
	}


Top ↑

Changelog

Changelog
Version Description
5.9.0 Added the $origins parameter.
5.8.0 Introduced.

Top ↑

User Contributed Notes

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