WP_Theme_JSON::get_default_slugs() – 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.

You appear to be a bot. Output may be restricted

Description

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.

For example: array(

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

)

Usage

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

Parameters

$data
( array ) required – A theme.json like structure.
$node_path
( array ) required – The path to inspect. It's 'settings' by default.

Returns

array

Source

File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:

1 to 22 of 22
  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;
  }
 

 View on GitHub View on Trac