WP_Theme_JSON::__construct( array $theme_json = array(), string $origin = ‘theme’ )

In this article

Constructor.

Parameters

$theme_jsonarrayoptional
A structure that follows the theme.json schema.

Default:array()

$originstringoptional
What source of data this object represents.
One of 'default', 'theme', or 'custom'. Default 'theme'.

Default:'theme'

Source

const LATEST_SCHEMA = 2;

/**
 * Constructor.
 *
 * @since 5.8.0
 *
 * @param array  $theme_json A structure that follows the theme.json schema.
 * @param string $origin     Optional. What source of data this object represents.
 *                           One of 'default', 'theme', or 'custom'. Default 'theme'.
 */
public function __construct( $theme_json = array(), $origin = 'theme' ) {
	if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) {
		$origin = 'theme';
	}

	$this->theme_json    = WP_Theme_JSON_Schema::migrate( $theme_json );
	$valid_block_names   = array_keys( static::get_blocks_metadata() );
	$valid_element_names = array_keys( static::ELEMENTS );
	$valid_variations    = array();
	foreach ( self::get_blocks_metadata() as $block_name => $block_meta ) {
		if ( ! isset( $block_meta['styleVariations'] ) ) {
			continue;
		}
		$valid_variations[ $block_name ] = array_keys( $block_meta['styleVariations'] );
	}
	$theme_json       = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations );
	$this->theme_json = static::maybe_opt_in_into_settings( $theme_json );

	// Internally, presets are keyed by origin.
	$nodes = static::get_setting_nodes( $this->theme_json );
	foreach ( $nodes as $node ) {
		foreach ( static::PRESETS_METADATA as $preset_metadata ) {
			$path = $node['path'];
			foreach ( $preset_metadata['path'] as $subpath ) {
				$path[] = $subpath;

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

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