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’ ), ), )
Parameters
- $data
(array)(Required)A theme.json like structure.
- $node_path
(array)(Required)The path to inspect. It's 'settings' by default.
Return
(array)
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |