WordPress at a glance
function is not described

WP_Widget_Media::update() public WP 4.8.0

Sanitizes the widget form values as they are saved.

{} It's a method of the class: WP_Widget_Media{}

No Hooks.

Return

Array. Updated safe values to be saved.

Usage

$WP_Widget_Media = new WP_Widget_Media();
$WP_Widget_Media->update( $new_instance, $instance );
$new_instance(array) (required)
Values just sent to be saved.
$instance(array) (required)
Previously saved values from database.

Notes

  • See: WP_Widget::update()
  • See: WP_REST_Request::has_valid_params()
  • See: WP_REST_Request::sanitize_params()

Changelog

Since 4.8.0 Introduced.

Code of WP_Widget_Media::update() WP 5.7.2

<?php
public function update( $new_instance, $instance ) {

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

		/*
		 * Workaround 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_sanitize_value_from_schema( $value, $field_schema );

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

		// @codeCoverageIgnoreEnd
		if ( isset( $field_schema['sanitize_callback'] ) ) {
			$value = call_user_func( $field_schema['sanitize_callback'], $value );
		}
		if ( is_wp_error( $value ) ) {
			continue;
		}
		$instance[ $field ] = $value;
	}

	return $instance;
}