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

) {
	foreach ( $spacing_rules as $spacing_rule ) {
		$declarations = array();
		if (
			isset( $spacing_rule['selector'] ) &&
			preg_match( $layout_selector_pattern, $spacing_rule['selector'] ) &&
			! empty( $spacing_rule['rules'] )
		) {
			// Iterate over each of the styling rules and substitute non-string values such as `null` with the real `blockGap` value.
			foreach ( $spacing_rule['rules'] as $css_property => $css_value ) {
				$current_css_value = is_string( $css_value ) ? $css_value : $block_gap_value;
				if ( static::is_safe_css_declaration( $css_property, $current_css_value ) ) {
					$declarations[] = array(
						'name'  => $css_property,
						'value' => $current_css_value,
					);
				}
			}

			if ( ! $has_block_gap_support ) {
				// For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
				$format          = static::ROOT_BLOCK_SELECTOR === $selector ? ':where(.%2$s%3$s)' : ':where(%1$s.%2$s%3$s)';
				$layout_selector = sprintf(
					$format,
					$selector,
					$class_name,
					$spacing_rule['selector']
				);
			} else {
				$format          = static::ROOT_BLOCK_SELECTOR === $selector ? ':root :where(.%2$s)%3$s' : ':root :where(%1$s-%2$s)%3$s';
				$layout_selector = sprintf(

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

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