WP_Theme_JSON::remove_keys_not_in_schema()
Given a tree, removes the keys that are not present in the schema.
It is recursive and modifies the input in-place.
Метод класса: WP_Theme_JSON{}
Хуков нет.
Возвращает
Массив
. The modified $tree.
Использование
$result = WP_Theme_JSON::remove_keys_not_in_schema( $tree, $schema );
- $tree(массив) (обязательный)
- Input to process.
- $schema(массив) (обязательный)
- Schema to adhere to.
Список изменений
С версии 5.8.0 | Введена. |
Код WP_Theme_JSON::remove_keys_not_in_schema() WP Theme JSON::remove keys not in schema WP 6.2.2
protected static function remove_keys_not_in_schema( $tree, $schema ) { $tree = array_intersect_key( $tree, $schema ); foreach ( $schema as $key => $data ) { if ( ! isset( $tree[ $key ] ) ) { continue; } if ( is_array( $schema[ $key ] ) && is_array( $tree[ $key ] ) ) { $tree[ $key ] = static::remove_keys_not_in_schema( $tree[ $key ], $schema[ $key ] ); if ( empty( $tree[ $key ] ) ) { unset( $tree[ $key ] ); } } elseif ( is_array( $schema[ $key ] ) && ! is_array( $tree[ $key ] ) ) { unset( $tree[ $key ] ); } } return $tree; }