WordPress at Your Fingertips
function is not described

WP_Theme_JSON::remove_keys_not_in_schema() private WP 5.8.0

Given a tree, removes the keys that are not present in the schema.

It is recursive and modifies the input in-place.

{} It's a method of the class: WP_Theme_JSON{}

No Hooks.

Return

Array. Returns the modified $tree.

Usage

$result = WP_Theme_JSON::remove_keys_not_in_schema( $tree, $schema );
$tree(array) (required)
Input to process.
$schema(array) (required)
Schema to adhere to.

Changelog

Since 5.8.0 Introduced.

Code of WP_Theme_JSON::remove_keys_not_in_schema() WP 5.8.2

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