WordPress at Your Fingertips
function is not described

WP_Theme_JSON::get_merged_preset_by_slug() private WP 5.8.0

Given an array of presets keyed by origin and the value key of the preset, it returns an array where each key is the preset slug and each value the preset value.

{} It's a method of the class: WP_Theme_JSON{}

No Hooks.

Return

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

Usage

$result = WP_Theme_JSON::get_merged_preset_by_slug( $preset_per_origin, $value_key );
$preset_per_origin(array) (required)
Array of presets keyed by origin.
$value_key(string) (required)
The property of the preset that contains its value.

Changelog

Since 5.8.0 Introduced.

Code of WP_Theme_JSON::get_merged_preset_by_slug() WP 5.8.2

private static function get_merged_preset_by_slug( $preset_per_origin, $value_key ) {
	$result = array();
	foreach ( self::VALID_ORIGINS as $origin ) {
		if ( ! isset( $preset_per_origin[ $origin ] ) ) {
			continue;
		}
		foreach ( $preset_per_origin[ $origin ] as $preset ) {
			/*
			 * We don't want to use kebabCase here,
			 * see https://github.com/WordPress/gutenberg/issues/32347
			 * However, we need to make sure the generated class or CSS variable
			 * doesn't contain spaces.
			 */
			$result[ preg_replace( '/\s+/', '-', $preset['slug'] ) ] = $preset[ $value_key ];
		}
	}
	return $result;
}