WP_Theme_JSON::preserve_valid_typed_settings( array $input, array $output, array $schema, array $path = array() )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

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

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.