WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Theme_JSON::flatten_tree() private WP 5.8.0

Given a tree, it creates a flattened one by merging the keys and binding the leaf values to the new keys.

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

{} Это метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

Массив. The flattened tree.

Использование

$result = WP_Theme_JSON::flatten_tree( $tree, $prefix, $token );
$tree(массив) (обязательный)
Input tree to process.
$prefix(строка)
Prefix to prepend to each variable.
По умолчанию: empty string
$token(строка)
Token to use between levels.
По умолчанию: '--'

Список изменений

С версии 5.8.0 Введена.

Код WP_Theme_JSON::flatten_tree() WP 5.8.1

private static function flatten_tree( $tree, $prefix = '', $token = '--' ) {
	$result = array();
	foreach ( $tree as $property => $value ) {
		$new_key = $prefix . str_replace(
			'/',
			'-',
			strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $property ) ) // CamelCase to kebab-case.
		);

		if ( is_array( $value ) ) {
			$new_prefix = $new_key . $token;
			$result     = array_merge(
				$result,
				self::flatten_tree( $value, $new_prefix, $token )
			);
		} else {
			$result[ $new_key ] = $value;
		}
	}
	return $result;
}