wppaste
WordPress

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

Since
5.8.0, 5.9.0, 6.1.0, 6.2.0
Source
wp-includes/class-wp-theme-json-resolver.php:652
Returns the data merged from multiple origins.

Description

There are four sources of data (origins) for a site:

  • default => WordPress
  • blocks => each one of the blocks provides data for itself
  • theme => the active theme
  • custom => data provided by the user

The custom's has higher priority than the theme's, the theme's higher than blocks', and block's higher than default's.

Unlike the getters https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data, https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data, and https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ 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 (default, blocks, theme, custom), 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.

Compatibility

WordPress
since 6.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$originstringoptional
To what level should we merge data: 'default', 'blocks', 'theme' or 'custom'.
'custom' is used as default value as well as fallback value if the origin is unknown.Default: 'custom'

Return value

WP_Theme_JSON

Performance profile

How much work a call to WP_Theme_JSON_Resolver::get_merged_data() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
14–37

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 40.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
10

10 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below WP_Theme_JSON_Resolver::get_merged_data()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 8 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme_JSON_Resolver::get_merged_data() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!is_array($origin) && $origin === "default"14::get_core_data(), ->merge()
is_array($origin) && $origin === "default"18_deprecated_argument(), ::get_core_data(), ->merge()
!is_array($origin) && $origin !== "default" && $origin === "blocks"21::get_core_data(), ->merge(), ::get_block_data(), ->merge()
is_array($origin) && $origin !== "default" && $origin === "blocks"25_deprecated_argument(), ::get_core_data(), ->merge(), ::get_block_data(), ->merge()
!is_array($origin) && $origin !== "default" && $origin !== "blocks" && $origin === "theme"28::get_core_data(), ->merge(), ::get_block_data(), ->merge(), ::get_theme_data(), ->merge()
is_array($origin) && $origin !== "default" && $origin !== "blocks" && $origin === "theme"32_deprecated_argument(), ::get_core_data(), ->merge(), ::get_block_data(), ->merge(), ::get_theme_data(), ->merge()
!is_array($origin) && $origin !== "default" && $origin !== "blocks" && $origin !== "theme"33::get_core_data(), ->merge(), ::get_block_data(), ->merge(), ::get_theme_data(), ->merge(), ::get_user_data(), ->merge()
is_array($origin) && $origin !== "default" && $origin !== "blocks" && $origin !== "theme"37_deprecated_argument(), ::get_core_data(), ->merge(), ::get_block_data(), ->merge(), ::get_theme_data(), ->merge(), ::get_user_data(), ->merge()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 40 instructions, 14–37 executed per call, 4 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 6

Used by · 10

Source code

	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() );		if ( 'default' === $origin ) {			return $result;		} 		$result->merge( static::get_block_data() );		if ( 'blocks' === $origin ) {			return $result;		} 		$result->merge( static::get_theme_data() );		if ( 'theme' === $origin ) {			return $result;		} 		$result->merge( static::get_user_data() ); 		return $result;	}

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.2.0
Changed ' $origin' parameter values to 'default', 'blocks', 'theme' or 'custom'.from the docblock
6.1.0
Added block data and generation of spacingSizes array.from the docblock
5.9.0
Added user data, removed the $settings parameter, added the $origin parameter.from the docblock
5.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-theme-json-resolver.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.