WP_Theme_JSON::__construct() – Constructor.
You appear to be a bot. Output may be restricted
Description
Constructor.
Usage
WP_Theme_JSON::__construct( $theme_json, $origin );
Parameters
- $theme_json
- ( array ) optional – A structure that follows the theme.json schema.
- $origin
- ( string ) optional default: theme – Optional. What source of data this object represents. One of 'default', 'theme', or 'custom'. Default 'theme'.
Returns
void
Source
File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:
1 to 30 of 30
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 ); $theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names ); $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; } $preset = _wp_array_get( $this->theme_json, $path, null ); if ( null !== $preset ) { // If the preset is not already keyed by origin. if ( isset( $preset[0] ) || empty( $preset ) ) { _wp_array_set( $this->theme_json, $path, array( $origin => $preset ) ); } } } } }