WP_Theme_JSON::get_default_slugs( array $data, array $node_path ): array

Returns the default slugs for all the presets in an associative array whose keys are the preset paths and the leaves is the list of slugs.

Description

For example:

array(
  'color' => array(
    'palette'   => array( 'slug-1', 'slug-2' ),
    'gradients' => array( 'slug-3', 'slug-4' ),
  ),
)

Parameters

$dataarrayrequired
A theme.json like structure.
$node_patharrayrequired
The path to inspect. It’s 'settings' by default.

Return

array

Source

protected static function get_default_slugs( $data, $node_path ) {
	$slugs = array();

	foreach ( static::PRESETS_METADATA as $metadata ) {
		$path = $node_path;
		foreach ( $metadata['path'] as $leaf ) {
			$path[] = $leaf;
		}
		$path[] = 'default';

		$preset = _wp_array_get( $data, $path, null );
		if ( ! isset( $preset ) ) {
			continue;
		}

		$slugs_for_preset = array();
		foreach ( $preset as $item ) {
			if ( isset( $item['slug'] ) ) {
				$slugs_for_preset[] = $item['slug'];
			}
		}

		_wp_array_set( $slugs, $metadata['path'], $slugs_for_preset );
	}

	return $slugs;
}

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

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