WP_Customize_Setting::multidimensional
Multidimensional helper function.
Method of the class: WP_Customize_Setting{}
No Hooks.
Returns
Array|null. Keys are 'root', 'node', and 'key'.
Usage
// protected - for code of main (parent) or child class $result = $this->multidimensional( $root, $keys, $create );
- $root(array) (required) (passed by reference — &)
- .
- $keys(array) (required)
- .
- $create(true|false)
- Default false.
Default:false
Changelog
| Since 3.4.0 | Introduced. |
WP_Customize_Setting::multidimensional() WP Customize Setting::multidimensional code WP 6.9.1
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,
);
}