WP_Theme_JSON::preserve_valid_typed_settings
Preserves valid typed settings from input to output based on type markers in schema.
Recursively iterates through the schema and validates/preserves settings that have type markers (e.g., boolean) in VALID_SETTINGS.
Method of the class: WP_Theme_JSON{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WP_Theme_JSON::preserve_valid_typed_settings( $input, $output, $schema, $path );
- $input(array) (required)
- Input settings to process.
- $output(array) (required) (passed by reference — &)
- Output settings array (passed by reference).
- $schema(array) (required)
- Schema to validate against (typically VALID_SETTINGS).
- $path(array<string|int>)
- Current path in the schema (for recursive calls).
Default:array()
Changelog
| Since 7.0.0 | Introduced. |
WP_Theme_JSON::preserve_valid_typed_settings() WP Theme JSON::preserve valid typed settings code WP 7.0
private static function preserve_valid_typed_settings( $input, &$output, $schema, $path = array() ) {
foreach ( $schema as $key => $schema_value ) {
$current_path = array_merge( $path, array( $key ) );
// Validate boolean type markers.
if ( is_bool( $schema_value ) ) {
$value = _wp_array_get( $input, $current_path, null );
if ( is_bool( $value ) ) {
_wp_array_set( $output, $current_path, $value ); // Preserve boolean value.
}
} elseif ( is_array( $schema_value ) ) {
self::preserve_valid_typed_settings( $input, $output, $schema_value, $current_path ); // Recurse into nested structure.
}
}
}