WP_Theme_JSON::get_metadata_boolean() WordPress Method

The WP_Theme_JSON::get_metadata_boolean() function is used to get the value of a theme's metadata field. The value is returned as a boolean (true/false).

WP_Theme_JSON::get_metadata_boolean( array $data, bool|array $path, bool $default = false ) #

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


Description

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

Top ↑

Parameters

$data

(array)(Required)The data to inspect.

$path

(bool|array)(Required)Boolean or path to a boolean.

$default

(bool)(Optional)Default value if the referenced path is missing.

Default value: false


Top ↑

Return

(bool) Value of boolean metadata.


Top ↑

Source

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

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


Top ↑

Changelog

Changelog
VersionDescription
6.0.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.