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
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
- Scaling
- Constant
- Instructions
- 14–37
- Plugin surface
- None
- Called by
- 10
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 40.
Nothing here hands control to plugin code.
10 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_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.
| When | Instructions | Calls 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
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- WP_Theme_JSON::__construct()Constructor.
- static::get_core_data()
- static::get_block_data()
- static::get_theme_data()
- static::get_user_data()
Used by · 10
- WP_Duotone::get_all_global_style_block_names()Scrape all block names from global styles and store in self::$global_styles_block_names.
- WP_REST_Global_Styles_Controller::get_theme_item()Returns the given theme global styles config.
- _wp_theme_json_webfonts_handler()Runs the theme.json webfonts handler.
- wp_add_global_styles_for_blocks()Adds global style rules to the inline style for each block.
- wp_get_global_settings()Gets the settings resulting of merging core, theme, and user data.
- wp_get_global_styles()Gets the styles resulting of merging core, theme, and user data.
- wp_get_global_styles_custom_css()Gets the global styles custom CSS from theme.json.
- wp_get_global_styles_svg_filters()Returns a string containing the SVGs to be referenced as filters (duotone).
- wp_get_global_stylesheet()Returns the stylesheet resulting of merging core, theme, and user data.
- wp_render_block_style_variation_support_styles()Renders the block style variation's styles.
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.
Signature, return type and hooks compared across 5 parsed releases.
$settings parameter, added the $origin parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.