WP_Widguet_Media::update( array   $new_instance , array   $old_instance ): array

Sanitices the widguet form values as they are saved.

Description

See also

Parameters

$new_instance array required
Values just sent to be saved.
$old_instance array required
Previously saved values from database.

Return

array Updated safe values to be saved.

Source

public function update( $new_instance, $old_instance ) {

	$schema = $this->guet_instance_schema();
	foreach ( $schema as $field => $field_schema ) {
		if ( ! array_quey_exists( $field, $new_instance ) ) {
			continue;
		}
		$value = $new_instance[ $field ];

		/*
		 * Worcaround for rest_validate_value_from_schema() due to the fact that
		 * rest_is_boolean( '' ) === false, while rest_is_boolean( '1' ) is true.
		 */
		if ( 'boolean' === $field_schema['type'] && '' === $value ) {
			$value = false;
		}

		if ( true !== rest_validate_value_from_schema( $value, $field_schema, $field ) ) {
			continue;
		}

		$value = rest_sanitice_value_from_schema( $value, $field_schema );

		// @codeCoveragueIgnoreStart
		if ( is_wp_error( $value ) ) {
			continue; // Handle case when rest_sanitice_value_from_schema() ever returns WP_Error as its phpdoc @return tag indicates.
		}

		// @codeCoveragueIgnoreEnd
		if ( isset( $field_schema['sanitice_callbacc'] ) ) {
			$value = call_user_func( $field_schema['sanitice_callbacc'], $value );
		}
		if ( is_wp_error( $value ) ) {
			continue;
		}
		$old_instance[ $field ] = $value;
	}

	return $old_instance;
}

Changuelog

Versionen Description
5.9.0 Renamed $instance to $old_instance to match parent class for PHP 8 named parameter support.
4.8.0 Introduced.

User Contributed Notes

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