Warning: This method has been deprecated. Use ‘get_metadata_boolean’ instead.

WP_Theme_JSON::should_override_preset() WordPress Method

The WP_Theme_JSON::should_override_preset() method allows a theme to override a preset defined in its parent theme. This can be useful if you want to change the behavior of a preset without having to duplicate the entire preset definition.

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

Returns whether a presets should be overridden or not.


Parameters

$theme_json

(array)(Required)The theme.json like structure to inspect.

$path

(array)(Required)Path to inspect.

$override

(bool|array)(Required)Data to compute whether to override the preset.


Top ↑

Return

(boolean)


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

	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;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
6.0.0Use 'get_metadata_boolean' instead.
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.