WP_Theme_JSON::compute_preset_classes() WordPress Method

This method is responsible for computing the preset CSS classes for a given theme. It first fetches the theme's preset CSS classes from the database, and then adds any custom CSS classes that have been added by the user. Finally, it adds any classes that are needed for specific theme features, such as 'has-header-image' or 'has-background-image'.

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

	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 = '';
		}

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

		return $stylesheet;
	}

Top ↑

Changelog

Changelog
VersionDescription
5.9.0Added the $origins parameter.
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.