WP_Theme_JSON::get_preset_classes() WordPress Method

The WP_Theme_JSON::get_preset_classes() method is used to get an array of preset CSS classes that are defined for a theme. These classes can be used to style elements in the theme.

WP_Theme_JSON::get_preset_classes( array $setting_nodes, array $origins ) #

Creates new rulesets as classes for each preset value such as:


Description

.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; }


Top ↑

Parameters

$setting_nodes

(array)(Required)Nodes with settings.

$origins

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


Top ↑

Return

(string) The new stylesheet.


Top ↑

Source

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

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


Top ↑

Changelog

Changelog
VersionDescription
5.9.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.