wp_theme_has_theme_json(): bool
- Since
- 6.2.0
- Source
wp-includes/global-styles-and-settings.php:391
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.
Return value
bool- Returns true if theme or its parent has a theme.json file, false otherwise.
Performance profile
How much work a call to wp_theme_has_theme_json() 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
- Heavy
- Scaling
- Constant
- Instructions
- 12–38
- Plugin surface
- 1 hook
- Called by
- 18
Reads or writes the filesystem via file_exists().
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 41.
Third-party callbacks on 'theme_file_path' run inside this call, and their cost is not bounded by anything here.
18 places 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 - filesystemfilesystem access
file_exists()called directly - optionoption read or write
get_option()one call below wp_theme_has_theme_json()
Further down the call graph this can also reach cache, serialize, 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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_theme_has_theme_json() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
isset($theme_has_support[$stylesheet]) && !wp_is_development_mode() | 12 | get_stylesheet(), wp_is_development_mode() |
!isset($theme_has_support[$stylesheet]) && $stylesheet_directory === false | 28 | get_stylesheet(), get_stylesheet_directory(), get_template_directory(), apply_filters(), file_exists() |
isset($theme_has_support[$stylesheet]) && wp_is_development_mode() && $stylesheet_directory === false | 32 | get_stylesheet(), wp_is_development_mode(), get_stylesheet_directory(), get_template_directory(), apply_filters(), file_exists() |
!isset($theme_has_support[$stylesheet]) && $stylesheet_directory !== false | 33–34 | get_stylesheet(), get_stylesheet_directory(), get_template_directory(), file_exists(), apply_filters(), file_exists() |
isset($theme_has_support[$stylesheet]) && wp_is_development_mode() && $stylesheet_directory !== false | 37–38 | get_stylesheet(), wp_is_development_mode(), get_stylesheet_directory(), get_template_directory(), file_exists(), apply_filters(), file_exists() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 41 instructions, 12–38 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.
Hooks and filters fired · 1
One hook fires while wp_theme_has_theme_json() runs, in this order:
- apply_filters( theme_file_path )filterline 418 (+27 into the body)
Filters the path to a file in the theme.
Uses · 5
- get_stylesheet()Retrieves name of the current stylesheet.
- wp_is_development_mode()Checks whether the site is in the given development mode.
- get_stylesheet_directory()Retrieves stylesheet directory path for the active theme.
- get_template_directory()Retrieves template directory path for the active theme.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 18
- WP_Duotone::restore_image_outer_container()Fixes the issue with our generated class name not being added to the block's outer container in classic themes due to gutenberg_restore_image_outer_container from layout block supports.
- WP_Theme_JSON_Resolver::get_theme_data()Returns the theme's data.
- WP_Theme_JSON_Resolver::theme_has_support()Determines whether the active theme has a theme.json file.
- _add_block_template_info()Attempts to add custom template information to the template item.
- _add_block_template_part_area_info()Attempts to add the template part's area information to the input template.
- _register_remote_theme_patterns()Registers patterns from Pattern Directory provided by a theme's `theme.json` file.
- _wp_get_iframed_editor_assets()Collect the block editor assets that need to be loaded into the editor's iframe.
- _wp_theme_json_webfonts_handler()Runs the theme.json webfonts handler.
- block_core_image_print_lightbox_overlay()
- wp_add_editor_classic_theme_styles()Loads classic theme styles on classic themes in the editor.
- wp_default_styles()Assigns default styles to $styles object.
- wp_enable_block_templates()Enables the block templates (editor mode) for themes with theme.json by default.
Show all 18
- wp_enqueue_classic_theme_styles()Loads classic theme styles when the current theme lacks a theme.json file.
- 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_restore_group_inner_container()For themes without theme.json file, make sure to restore the inner div for the group block to avoid breaking styles relying on that div.
- wp_restore_image_outer_container()For themes without theme.json file, make sure to restore the outer div for the aligned image block to avoid breaking styles relying on that div.
Source code
function wp_theme_has_theme_json() { static $theme_has_support = array(); $stylesheet = get_stylesheet(); if ( isset( $theme_has_support[ $stylesheet ] ) && /* * Ignore static cache when the development mode is set to 'theme', to avoid interfering with * the theme developer's workflow. */ ! wp_is_development_mode( 'theme' ) ) { return $theme_has_support[ $stylesheet ]; } $stylesheet_directory = get_stylesheet_directory(); $template_directory = get_template_directory(); // This is the same as get_theme_file_path(), which isn't available in load-styles.php context if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) { $path = $stylesheet_directory . '/theme.json'; } else { $path = $template_directory . '/theme.json'; } /** This filter is documented in wp-includes/link-template.php */ $path = apply_filters( 'theme_file_path', $path, 'theme.json' ); $theme_has_support[ $stylesheet ] = file_exists( $path ); return $theme_has_support[ $stylesheet ];}Changelog
Introduced in 6.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/global-styles-and-settings.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.