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
$treearray
Input tree to process.
$prefixstringoptional
Prefix to prepend to each variable. Default empty string.Default: ''
$tokenstringoptional
Token to use between levels. Default '--'.Default: '--'
Return
array
The flattened tree.
Uses · 2
_wp_to_kebab_case()This function is trying to replicate what lodash's kebabCase (JS library) does in the client.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-theme-json.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.