WP_Theme_JSON::get_metadata_boolean()protected staticWP 6.0.0

For metadata values that can either be booleans or paths to booleans, gets the value.

$data = array(
  'color' => array(
	'defaultPalette' => true
  )
);

static::get_metadata_boolean( $data, false );
// => false

static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) );
// => true

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

true|false. Value of boolean metadata.

Usage

$result = WP_Theme_JSON::get_metadata_boolean( $data, $path, $default );
$data(array) (required)
The data to inspect.
$path(true|false|array) (required)
Boolean or path to a boolean.
$default(true|false)
Default value if the referenced path is missing.
Default: false

Changelog

Since 6.0.0 Introduced.

WP_Theme_JSON::get_metadata_boolean() code WP 6.1.1

protected static function get_metadata_boolean( $data, $path, $default = false ) {
	if ( is_bool( $path ) ) {
		return $path;
	}

	if ( is_array( $path ) ) {
		$value = _wp_array_get( $data, $path );
		if ( null !== $value ) {
			return $value;
		}
	}

	return $default;
}