wppaste
WordPress

wp_get_global_settings( array $path = array(), array $context = array() ): mixed

Since
5.9.0
Source
wp-includes/global-styles-and-settings.php:26
Gets the settings resulting of merging core, theme, and user data.

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_namestring

    Which block to retrieve the settings from. If empty, it'll return the settings for the global context.
  • $originstring

    Which 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

Only touches the object cache, via wp_cache_get().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
25–55

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
7

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

What it touches

  • cacheobject cachewp_cache_get()called directly
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
$value && $settings !== false25–38wp_theme_has_theme_json(), wp_is_development_mode(), _wp_array_get()
!$value && $settings !== false30–43wp_theme_has_theme_json(), wp_is_development_mode(), wp_cache_get(), _wp_array_get()
$value && $settings === false32–45wp_theme_has_theme_json(), wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ->get_settings(), _wp_array_get()
$settings === false37–50wp_theme_has_theme_json(), wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ->get_settings(), wp_cache_set(), _wp_array_get()
$settings === false37–50wp_theme_has_theme_json(), wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ->get_settings(), _wp_array_get()
!$value && $settings === false42–55wp_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

Used by · 7

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.

  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.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 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.