WP_Theme_JSON::should_override_preset()protected staticWP 5.9.0

Deprecated from version 6.0.0. It is no longer supported and can be removed in future releases. See get_metadata_boolean.

Determines whether a presets should be overridden or not.

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

true|false.

Usage

$result = WP_Theme_JSON::should_override_preset( $theme_json, $path, $override );
$theme_json(array) (required)
The theme.json like structure to inspect.
$path(array) (required)
Path to inspect.
$override(true|false|array) (required)
Data to compute whether to override the preset.

Changelog

Since 5.9.0 Introduced.
Deprecated since 6.0.0 Use {@see 'get_metadata_boolean'} instead.

WP_Theme_JSON::should_override_preset() code WP 6.5.2

protected static function should_override_preset( $theme_json, $path, $override ) {
	_deprecated_function( __METHOD__, '6.0.0', 'get_metadata_boolean' );

	if ( is_bool( $override ) ) {
		return $override;
	}

	/*
	 * The relationship between whether to override the defaults
	 * and whether the defaults are enabled is inverse:
	 *
	 * - If defaults are enabled  => theme presets should not be overridden
	 * - If defaults are disabled => theme presets should be overridden
	 *
	 * For example, a theme sets defaultPalette to false,
	 * making the default palette hidden from the user.
	 * In that case, we want all the theme presets to be present,
	 * so they should override the defaults.
	 */
	if ( is_array( $override ) ) {
		$value = _wp_array_get( $theme_json, array_merge( $path, $override ) );
		if ( isset( $value ) ) {
			return ! $value;
		}

		// Search the top-level key if none was found for this node.
		$value = _wp_array_get( $theme_json, array_merge( array( 'settings' ), $override ) );
		if ( isset( $value ) ) {
			return ! $value;
		}

		return true;
	}
}