Title: WP_Theme_JSON::get_data
Published: May 25, 2022
Last modified: February 24, 2026

---

# WP_Theme_JSON::get_data(): array

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#wp--skip-link--target)

Returns a valid theme.json as provided by a theme.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#description)󠁿

Unlike get_raw_data() this returns the presets flattened, as provided by a theme.

This also uses appearanceTools instead of their opt-ins if all of them are true.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#return)󠁿

 array

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#source)󠁿

    ```php
    public function get_data() {
    	$output = $this->theme_json;
    	$nodes  = static::get_setting_nodes( $output );

    	/**
    	 * Flatten the theme & custom origins into a single one.
    	 *
    	 * For example, the following:
    	 *
    	 * {
    	 *   "settings": {
    	 *     "color": {
    	 *       "palette": {
    	 *         "theme": [ {} ],
    	 *         "custom": [ {} ]
    	 *       }
    	 *     }
    	 *   }
    	 * }
    	 *
    	 * will be converted to:
    	 *
    	 * {
    	 *   "settings": {
    	 *     "color": {
    	 *       "palette": [ {} ]
    	 *     }
    	 *   }
    	 * }
    	 */
    	foreach ( $nodes as $node ) {
    		foreach ( static::PRESETS_METADATA as $preset_metadata ) {
    			$path = $node['path'];
    			foreach ( $preset_metadata['path'] as $preset_metadata_path ) {
    				$path[] = $preset_metadata_path;
    			}
    			$preset = _wp_array_get( $output, $path, null );
    			if ( null === $preset ) {
    				continue;
    			}

    			$items = array();
    			if ( isset( $preset['theme'] ) ) {
    				foreach ( $preset['theme'] as $item ) {
    					$slug = $item['slug'];
    					unset( $item['slug'] );
    					$items[ $slug ] = $item;
    				}
    			}
    			if ( isset( $preset['custom'] ) ) {
    				foreach ( $preset['custom'] as $item ) {
    					$slug = $item['slug'];
    					unset( $item['slug'] );
    					$items[ $slug ] = $item;
    				}
    			}
    			$flattened_preset = array();
    			foreach ( $items as $slug => $value ) {
    				$flattened_preset[] = array_merge( array( 'slug' => (string) $slug ), $value );
    			}
    			_wp_array_set( $output, $path, $flattened_preset );
    		}
    	}

    	/*
    	 * If all of the static::APPEARANCE_TOOLS_OPT_INS are true,
    	 * this code unsets them and sets 'appearanceTools' instead.
    	 */
    	foreach ( $nodes as $node ) {
    		$all_opt_ins_are_set = true;
    		foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) {
    			$full_path = $node['path'];
    			foreach ( $opt_in_path as $opt_in_path_item ) {
    				$full_path[] = $opt_in_path_item;
    			}
    			/*
    			 * Use "unset prop" as a marker instead of "null" because
    			 * "null" can be a valid value for some props (e.g. blockGap).
    			 */
    			$opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' );
    			if ( 'unset prop' === $opt_in_value ) {
    				$all_opt_ins_are_set = false;
    				break;
    			}
    		}

    		if ( $all_opt_ins_are_set ) {
    			$node_path_with_appearance_tools   = $node['path'];
    			$node_path_with_appearance_tools[] = 'appearanceTools';
    			_wp_array_set( $output, $node_path_with_appearance_tools, true );
    			foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) {
    				$full_path = $node['path'];
    				foreach ( $opt_in_path as $opt_in_path_item ) {
    					$full_path[] = $opt_in_path_item;
    				}
    				/*
    				 * Use "unset prop" as a marker instead of "null" because
    				 * "null" can be a valid value for some props (e.g. blockGap).
    				 */
    				$opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' );
    				if ( true !== $opt_in_value ) {
    					continue;
    				}

    				/*
    				 * The following could be improved to be path independent.
    				 * At the moment it relies on a couple of assumptions:
    				 *
    				 * - all opt-ins having a path of size 2.
    				 * - there's two sources of settings: the top-level and the block-level.
    				 */
    				if (
    					( 1 === count( $node['path'] ) ) &&
    					( 'settings' === $node['path'][0] )
    				) {
    					// Top-level settings.
    					unset( $output['settings'][ $opt_in_path[0] ][ $opt_in_path[1] ] );
    					if ( empty( $output['settings'][ $opt_in_path[0] ] ) ) {
    						unset( $output['settings'][ $opt_in_path[0] ] );
    					}
    				} elseif (
    					( 3 === count( $node['path'] ) ) &&
    					( 'settings' === $node['path'][0] ) &&
    					( 'blocks' === $node['path'][1] )
    				) {
    					// Block-level settings.
    					$block_name = $node['path'][2];
    					unset( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ][ $opt_in_path[1] ] );
    					if ( empty( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ] ) ) {
    						unset( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ] );
    					}
    				}
    			}
    		}
    	}

    	wp_recursive_ksort( $output );

    	return $output;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-theme-json.php#L3914)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-theme-json.php#L3914-L4053)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_recursive_ksort()](https://developer.wordpress.org/reference/functions/wp_recursive_ksort/)`wp-includes/functions.php` |

Sorts the keys of an array alphabetically.

  | 
| [_wp_array_set()](https://developer.wordpress.org/reference/functions/_wp_array_set/)`wp-includes/functions.php` |

Sets an array in depth based on a path of keys.

  | 
| [_wp_array_get()](https://developer.wordpress.org/reference/functions/_wp_array_get/)`wp-includes/functions.php` |

Accesses an array in depth based on a path of keys.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/get_data/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_theme_json%2Fget_data%2F)
before being able to contribute a note or feedback.