Preserves valid typed settings from input to output based on type markers in schema.
Description
Recursively iterates through the schema and validates/preserves settings that have type markers (e.g., boolean) in VALID_SETTINGS.
Parameters
$inputarrayrequired- Input settings to process.
$outputarrayrequired- Output settings array (passed by reference).
$schemaarrayrequired- Schema to validate against (typically VALID_SETTINGS).
$path<span class="arrayarray<string|“>int>optional- Current path in the schema (for recursive calls).
Default:
array()
Source
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.
}
}
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.