WP_Customize_Setting::multidimensional() WordPress Method

The WP_Customize_Setting::multidimensional() method is used to retrieve or update the value of a multidimensional setting in the WordPress Customizer. This method can be used to get or set the value of a multidimensional setting in the WordPress Customizer. The first parameter is the key of the setting, and the second parameter is an array of data containing the new value of the setting. This method is especially useful for setting or updating the value of a multidimensional setting that is not represented by a single control in the Customizer. For example, a setting that consists of an array of data could be updated using this method.

WP_Customize_Setting::multidimensional( array $root, array $keys, bool $create = false ) #

Multidimensional helper function.


Parameters

$root

(array)(Required)

$keys

(array)(Required)

$create

(bool)(Optional)

Default value: false


Top ↑

Return

(array|void) Keys are 'root', 'node', and 'key'.


Top ↑

Source

File: wp-includes/class-wp-customize-setting.php

	final protected function multidimensional( &$root, $keys, $create = false ) {
		if ( $create && empty( $root ) ) {
			$root = array();
		}

		if ( ! isset( $root ) || empty( $keys ) ) {
			return;
		}

		$last = array_pop( $keys );
		$node = &$root;

		foreach ( $keys as $key ) {
			if ( $create && ! isset( $node[ $key ] ) ) {
				$node[ $key ] = array();
			}

			if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) {
				return;
			}

			$node = &$node[ $key ];
		}

		if ( $create ) {
			if ( ! is_array( $node ) ) {
				// Account for an array overriding a string or object value.
				$node = array();
			}
			if ( ! isset( $node[ $last ] ) ) {
				$node[ $last ] = array();
			}
		}

		if ( ! isset( $node[ $last ] ) ) {
			return;
		}

		return array(
			'root' => &$root,
			'node' => &$node,
			'key'  => $last,
		);
	}


Top ↑

Changelog

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