WordPress at Your Fingertips
function is not described

WP_Theme_JSON::__construct() public WP 5.8.0

Constructor.

{} It's a method of the class: WP_Theme_JSON{}

No Hooks.

Return

null. Nothing.

Usage

$WP_Theme_JSON = new WP_Theme_JSON();
$WP_Theme_JSON->__construct( $theme_json, $origin );
$theme_json(array)
A structure that follows the theme.json schema.
Default: array()
$origin(string)
What source of data this object represents. One of 'core', 'theme', or 'user'.
Default: 'theme'

Changelog

Since 5.8.0 Introduced.

Code of WP_Theme_JSON::__construct() WP 5.8.2

public function __construct( $theme_json = array(), $origin = 'theme' ) {
	if ( ! in_array( $origin, self::VALID_ORIGINS, true ) ) {
		$origin = 'theme';
	}

	if ( ! isset( $theme_json['version'] ) || self::LATEST_SCHEMA !== $theme_json['version'] ) {
		$this->theme_json = array();
		return;
	}

	$this->theme_json = self::sanitize( $theme_json );

	// Internally, presets are keyed by origin.
	$nodes = self::get_setting_nodes( $this->theme_json );
	foreach ( $nodes as $node ) {
		foreach ( self::PRESETS_METADATA as $preset ) {
			$path   = array_merge( $node['path'], $preset['path'] );
			$preset = _wp_array_get( $this->theme_json, $path, null );
			if ( null !== $preset ) {
				_wp_array_set( $this->theme_json, $path, array( $origin => $preset ) );
			}
		}
	}
}