wp_get_global_settings( array $path = array(), array $context = array() ): mixed
- Since
- 5.9.0
- Source
wp-includes/global-styles-and-settings.php:26
Compatibility
- WordPress
- since 5.9.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
$patharrayoptional- Path to the specific setting to retrieve. Optional.
If empty, will return all settings.Default:array() $contextarrayoptional- Metadata to know where to retrieve the $path from. Optional.Default:
array()$block_namestringWhich block to retrieve the settings from. If empty, it'll return the settings for the global context.$originstringWhich origin to take data from. Valid values are 'all' (core, theme, and user) or 'base' (core and theme). If empty or unknown, 'all' is used.
Return value
mixed- The settings array or individual setting value to retrieve.
Performance profile
How much work a call to wp_get_global_settings() 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
- Moderate
- Scaling
- Scales with input
- Instructions
- 25–55
- Plugin surface
- None
- Called by
- 7
Only touches the object cache, via wp_cache_get().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 58.
Nothing here hands control to plugin code.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_get()called directly - hookthird-party callbacks
apply_filters()one call below wp_get_global_settings()
Further down the call graph this can also reach option, 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_global_settings() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$value && $settings !== false | 25–38 | wp_theme_has_theme_json(), wp_is_development_mode(), _wp_array_get() |
!$value && $settings !== false | 30–43 | wp_theme_has_theme_json(), wp_is_development_mode(), wp_cache_get(), _wp_array_get() |
$value && $settings === false | 32–45 | wp_theme_has_theme_json(), wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ->get_settings(), _wp_array_get() |
$settings === false | 37–50 | wp_theme_has_theme_json(), wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ->get_settings(), wp_cache_set(), _wp_array_get() |
$settings === false | 37–50 | wp_theme_has_theme_json(), wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ->get_settings(), _wp_array_get() |
!$value && $settings === false | 42–55 | wp_theme_has_theme_json(), wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ->get_settings(), wp_cache_set(), _wp_array_get() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 58 instructions, 25–55 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.
Uses · 7
- wp_theme_has_theme_json()Checks whether a theme or its parent has a theme.json file.
- wp_is_development_mode()Checks whether the site is in the given development mode.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- wp_cache_set()Saves the data to the cache.
- _wp_array_get()Accesses an array in depth based on a path of keys.
- WP_Theme_JSON_Resolver::get_merged_data($origin)::get_settings()
- WP_Theme_JSON_Resolver::get_merged_data()Returns the data merged from multiple origins.
Used by · 7
- WP_Duotone::get_all_global_styles_presets()Scrape all possible duotone presets from global and theme styles and store them in self::$global_styles_presets.
- WP_Font_Face_Resolver::get_fonts_from_theme_json()Gets fonts defined in theme.json.
- block_core_image_get_lightbox_settings()Adds the lightboxEnabled flag to the block data.
- get_block_editor_settings()Returns the contextualized block editor settings for a selected editor context.
- wp_get_typography_font_size_value()Returns a font-size value based on a given font-size preset.
- wp_render_layout_support_flag()Renders the layout config to the block wrapper.
- wp_render_position_support()Renders position styles to the block wrapper.
Source code
function wp_get_global_settings( $path = array(), $context = array() ) { if ( ! empty( $context['block_name'] ) ) { $new_path = array( 'blocks', $context['block_name'] ); foreach ( $path as $subpath ) { $new_path[] = $subpath; } $path = $new_path; } /* * This is the default value when no origin is provided or when it is 'all'. * * The $origin is used as part of the cache key. Changes here need to account * for clearing the cache appropriately. */ $origin = 'custom'; if ( ! wp_theme_has_theme_json() || ( isset( $context['origin'] ) && 'base' === $context['origin'] ) ) { $origin = 'theme'; } /* * By using the 'theme_json' group, this data is marked to be non-persistent across requests. * See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php and other places. * * The rationale for this is to make sure derived data from theme.json * is always fresh from the potential modifications done via hooks * that can use dynamic data (modify the stylesheet depending on some option, * settings depending on user permissions, etc.). * See some of the existing hooks to modify theme.json behavior: * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ * * A different alternative considered was to invalidate the cache upon certain * events such as options add/update/delete, user meta, etc. * It was judged not enough, hence this approach. * See https://github.com/WordPress/gutenberg/pull/45372 */ $cache_group = 'theme_json'; $cache_key = 'wp_get_global_settings_' . $origin; /* * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme * developer's workflow. */ $can_use_cached = ! wp_is_development_mode( 'theme' ); $settings = false; if ( $can_use_cached ) { $settings = wp_cache_get( $cache_key, $cache_group ); } if ( false === $settings ) { $settings = WP_Theme_JSON_Resolver::get_merged_data( $origin )->get_settings(); if ( $can_use_cached ) { wp_cache_set( $cache_key, $settings, $cache_group ); } } return _wp_array_get( $settings, $path, $settings );}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.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.