WP_Theme_JSON::remove_keys_not_in_schema( array $tree, array $schema )
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Given a tree, removes the keys that are not present in the schema.
Description
It is recursive and modifies the input in-place.
Parameters
- $tree
-
(array) (Required) Input to process.
- $schema
-
(array) (Required) Schema to adhere to.
Return
(array) Returns the modified $tree.
Source
File: wp-includes/class-wp-theme-json.php
private 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 ] = self::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; }
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme_json/remove_keys_not_in_schema