WP_Theme_JSON::flatten_tree( array $tree, string $prefix = '', string $token = '--' ): array
Given a tree, it creates a flattened one by merging the keys and binding the leaf values to the new keys.
Description
It also transforms camelCase names into kebab-case and substitutes ‘/’ by ‘-‘.
This is thought to be useful to generate CSS Custom Properties from a tree, although there’s nothing in the implementation of this function that requires that format.
For example, assuming the given prefix is ‘–wp’ and the token is ‘–‘, for this input tree:
{
'some/property': 'value',
'nestedProperty': {
'sub-property': 'value'
}
}
it’ll return this output:
{
'--wp--some-property': 'value',
'--wp--nested-property--sub-property': 'value'
}
Parameters
-
$tree
array Required -
Input tree to process.
-
$prefix
string Optional -
Prefix to prepend to each variable.
Default:
''
-
$token
string Optional -
Token to use between levels. Default
'--'
.Default:
'--'
Return
array The flattened tree.
Source
File: wp-includes/class-wp-theme-json.php
.
View all references
*
* It also transforms camelCase names into kebab-case
* and substitutes '/' by '-'.
*
* This is thought to be useful to generate
* CSS Custom Properties from a tree,
* although there's nothing in the implementation
* of this function that requires that format.
*
* For example, assuming the given prefix is '--wp'
* and the token is '--', for this input tree:
*
* {
* 'some/property': 'value',
* 'nestedProperty': {
* 'sub-property': 'value'
* }
* }
*
* it'll return this output:
*
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |