WP_Theme_JSON_Resolver::get_merged_data() WordPress Method

WP_Theme_JSON_Resolver::get_merged_data is a method that allows a WordPress theme to resolve data from multiple JSON files. The method accepts an array of file names as its first parameter. The method returns a merged array of data from the specified JSON files.

WP_Theme_JSON_Resolver::get_merged_data( string $origin = 'custom' ) #

Returns the data merged from multiple origins.


Description

There are three sources of data (origins) for a site: default, theme, and custom. The custom’s has higher priority than the theme’s, and the theme’s higher than default’s.

Unlike the getters get_core_data, get_theme_data, and get_user_data, this method returns data after it has been merged with the previous origins. This means that if the same piece of data is declared in different origins (user, theme, and core), the last origin overrides the previous.

For example, if the user has set a background color for the paragraph block, and the theme has done it as well, the user preference wins.


Top ↑

Parameters

$origin

(string)(Optional) To what level should we merge data. Valid values are 'theme' or 'custom'.

Default value: 'custom'


Top ↑

Return

(WP_Theme_JSON)


Top ↑

Source

File: wp-includes/class-wp-theme-json-resolver.php

	public static function get_merged_data( $origin = 'custom' ) {
		if ( is_array( $origin ) ) {
			_deprecated_argument( __FUNCTION__, '5.9.0' );
		}

		$result = new WP_Theme_JSON();
		$result->merge( static::get_core_data() );
		$result->merge( static::get_theme_data() );

		if ( 'custom' === $origin ) {
			$result->merge( static::get_user_data() );
		}

		return $result;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Added user data, removed the $settings parameter, added the $origin parameter.
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.