WP_Theme_JSON::remove_keys_not_in_schema() WordPress Method
The WP_Theme_JSON::remove_keys_not_in_schema() function is used to remove any extra keys that are not specified in the schema for the current theme. This is useful for making sure that only the data that is needed is stored in the database.
WP_Theme_JSON::remove_keys_not_in_schema( array $tree, array $schema ) #
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
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |