WP_Theme_JSON::should_override_preset( array $theme_json, array $path, bool|array $override ): boolean

In this article

This method has been deprecated. Use {@see ‘get_metadata_boolean’} instead.

Determines whether a presets should be overridden or not.


The theme.json like structure to inspect.
Path to inspect.
Data to compute whether to override the preset.




$incoming_data    = $incoming->get_raw_data();
$this->theme_json = array_replace_recursive( $this->theme_json, $incoming_data );

 * The array_replace_recursive algorithm merges at the leaf level,
 * but we don't want leaf arrays to be merged, so we overwrite it.
 * For leaf values that are sequential arrays it will use the numeric indexes for replacement.
 * We rather replace the existing with the incoming value, if it exists.
 * This is the case of spacing.units.
 * For leaf values that are associative arrays it will merge them as expected.
 * This is also not the behavior we want for the current associative arrays (presets).
 * We rather replace the existing with the incoming value, if it exists.
 * This happens, for example, when we merge data from theme.json upon existing
 * theme supports or when we merge anything coming from the same source twice.
 * This is the case of color.palette, color.gradients, color.duotone,
 * typography.fontSizes, or typography.fontFamilies.
 * Additionally, for some preset types, we also want to make sure the
 * values they introduce don't conflict with default values. We do so
 * by checking the incoming slugs for theme presets and compare them
 * with the equivalent default presets: if a slug is present as a default
 * we remove it from the theme presets.
$nodes        = static::get_setting_nodes( $incoming_data );
$slugs_global = static::get_default_slugs( $this->theme_json, array( 'settings' ) );
foreach ( $nodes as $node ) {
	// Replace the spacing.units.
	$path   = $node['path'];
	$path[] = 'spacing';
	$path[] = 'units';

	$content = _wp_array_get( $incoming_data, $path, null );


6.0.0Use 'get_metadata_boolean' instead.

User Contributed Notes

You must log in before being able to contribute a note or feedback.