WP_Theme_JSON::get_default_slugs() WordPress Method

The WP_Theme_JSON::get_default_slugs() function is used to get an array of default slugs for the current theme.

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

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


Description

For example:

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


Top ↑

Parameters

$data

(array)(Required)A theme.json like structure.

$node_path

(array)(Required)The path to inspect. It's 'settings' by default.


Top ↑

Return

(array)


Top ↑

Source

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

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

		foreach ( static::PRESETS_METADATA as $metadata ) {
			$path   = array_merge( $node_path, $metadata['path'], array( 'default' ) );
			$preset = _wp_array_get( $data, $path, null );
			if ( ! isset( $preset ) ) {
				continue;
			}

			$slugs_for_preset = array();
			$slugs_for_preset = array_map(
				static function( $value ) {
					return isset( $value['slug'] ) ? $value['slug'] : null;
				},
				$preset
			);
			_wp_array_set( $slugs, $metadata['path'], $slugs_for_preset );
		}

		return $slugs;
	}


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.