WP_Theme_JSON::get_settings_values_by_slug( array $settings, array $preset_metadata, string[] $origins ): array

In this article

Gets preset values keyed by slugs based on settings and metadata.

Description

$settings = array(
    'typography' => array(
        'fontFamilies' => array(
            array(
                'slug'       => 'sansSerif',
                'fontFamily' => '"Helvetica Neue", sans-serif',
            ),
            array(
                'slug'   => 'serif',
                'colors' => 'Georgia, serif',
            )
        ),
    ),
);
$meta = array(
   'path'      => array( 'typography', 'fontFamilies' ),
   'value_key' => 'fontFamily',
);
$values_by_slug = get_settings_values_by_slug();
// $values_by_slug === array(
//   'sans-serif' => '"Helvetica Neue", sans-serif',
//   'serif'      => 'Georgia, serif',
// );

Parameters

$settingsarrayrequired
Settings to process.
$preset_metadataarrayrequired
One of the PRESETS_METADATA values.
$originsstring[]required
List of origins to process.

Return

array Array of presets where each key is a slug and each value is the preset value.

Source


	$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.0Introduced.

User Contributed Notes

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