WP_Theme_JSON_Resolver::get_user_data(): WP_Theme_JSON
- Since
- 5.9.0, 6.6.0
- Source
wp-includes/class-wp-theme-json-resolver.php:543
Compatibility
- WordPress
- since 6.6.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.
Return value
WP_Theme_JSON- Entity that holds styles for user data.
Performance profile
How much work a call to WP_Theme_JSON_Resolver::get_user_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
- 9–56
- Plugin surface
- 1 hook
- Called by
- 1
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 92.
Third-party callbacks on 'wp_theme_json_data_user' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - serializeserialisation
json_decode()called directly
Further down the call graph this can also reach option, cache, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 13 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_user_data() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
::has_same_registered_blocks() | 9 | ::has_same_registered_blocks() |
!$user_cpt && $theme_json instanceof | 30 | wp_get_theme(), ::get_user_data_from_wp_global_styles(), apply_filters(), ->get_theme_json() |
!$user_cpt && !($theme_json instanceof) | 34 | wp_get_theme(), ::get_user_data_from_wp_global_styles(), apply_filters(), ->get_data() |
!::has_same_registered_blocks() && !$user_cpt && $theme_json instanceof | 34 | ::has_same_registered_blocks(), wp_get_theme(), ::get_user_data_from_wp_global_styles(), apply_filters(), ->get_theme_json() |
!::has_same_registered_blocks() && !$user_cpt && !($theme_json instanceof) | 38 | ::has_same_registered_blocks(), wp_get_theme(), ::get_user_data_from_wp_global_styles(), apply_filters(), ->get_data() |
$user_cpt && $json_decoding_error === 0 && $theme_json instanceof | 42–48 | wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), apply_filters(), ->get_theme_json() |
$user_cpt && $json_decoding_error !== 0 && $theme_json instanceof | 43 | wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), json_last_error_msg(), wp_trigger_error(), apply_filters(), ->get_theme_json() |
$user_cpt && $json_decoding_error === 0 && !($theme_json instanceof) | 46–52 | wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), apply_filters(), ->get_data() |
!::has_same_registered_blocks() && $user_cpt && $json_decoding_error === 0 && $theme_json instanceof | 46–52 | ::has_same_registered_blocks(), wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), apply_filters(), ->get_theme_json() |
!::has_same_registered_blocks() && $user_cpt && $json_decoding_error !== 0 && $theme_json instanceof | 47 | ::has_same_registered_blocks(), wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), json_last_error_msg(), wp_trigger_error(), apply_filters(), ->get_theme_json() |
$user_cpt && $json_decoding_error !== 0 && !($theme_json instanceof) | 48 | wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), json_last_error_msg(), wp_trigger_error(), apply_filters(), ->get_data() |
!::has_same_registered_blocks() && $user_cpt && $json_decoding_error === 0 && !($theme_json instanceof) | 50–56 | ::has_same_registered_blocks(), wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), apply_filters(), ->get_data() |
1 further outcome, up to 52 instructions
!::has_same_registered_blocks() && $user_cpt && $json_decoding_error !== 0 && !($theme_json instanceof) | 52 | ::has_same_registered_blocks(), wp_get_theme(), ::get_user_data_from_wp_global_styles(), json_decode(), json_last_error(), json_last_error_msg(), wp_trigger_error(), apply_filters(), ->get_data() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 92 instructions, 9–56 executed per call, 9 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.
Hooks and filters fired · 2
2 hooks fire while WP_Theme_JSON_Resolver::get_user_data() runs, in this order:
- apply_filters( wp_theme_json_data_user )filterline 564 (+21 into the body)
Filters the data provided by the user for global styles & settings.
- apply_filters( wp_theme_json_data_user )filterline 593 (+50 into the body)
Filters the data provided by the user for global styles & settings.
Uses · 7
- wp_get_theme()Gets a WP_Theme object for a theme.
- wp_trigger_error()Generates a user-level error/warning/notice/deprecation message.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- static::has_same_registered_blocks()
- static::get_user_data_from_wp_global_styles()
- WP_Theme_JSON_Data::__construct()Constructor.
- WP_Theme_JSON::__construct()Constructor.
Used by · 1
- wp_generate_block_templates_export_file()Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file.
Source code
public static function get_user_data() { if ( null !== static::$user && static::has_same_registered_blocks( 'user' ) ) { return static::$user; } $config = array(); $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() ); if ( array_key_exists( 'post_content', $user_cpt ) ) { $decoded_data = json_decode( $user_cpt['post_content'], true ); $json_decoding_error = json_last_error(); if ( JSON_ERROR_NONE !== $json_decoding_error ) { wp_trigger_error( __METHOD__, 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() ); /** * Filters the data provided by the user for global styles & settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); /* * Backward compatibility for extenders returning a WP_Theme_JSON_Data * compatible class that is not a WP_Theme_JSON_Data object. */ if ( $theme_json instanceof WP_Theme_JSON_Data ) { return $theme_json->get_theme_json(); } else { $config = $theme_json->get_data(); return new WP_Theme_JSON( $config, 'custom' ); } } /* * Very important to verify that the flag isGlobalStylesUserThemeJSON is true. * If it's not true then the content was not escaped and is not safe. */ if ( is_array( $decoded_data ) && isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) && $decoded_data['isGlobalStylesUserThemeJSON'] ) { unset( $decoded_data['isGlobalStylesUserThemeJSON'] ); $config = $decoded_data; } } /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); /* * Backward compatibility for extenders returning a WP_Theme_JSON_Data * compatible class that is not a WP_Theme_JSON_Data object. */ if ( $theme_json instanceof WP_Theme_JSON_Data ) { static::$user = $theme_json->get_theme_json(); } else { $config = $theme_json->get_data(); static::$user = new WP_Theme_JSON( $config, 'custom' ); } return static::$user; }Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
Register the block style variations coming from the user data.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.