WordPress at Your Fingertips
function is not described

WC_Widget::update() public WC 1.0

Updates a particular instance of a widget.

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

Return

Array.

Usage

$WC_Widget = new WC_Widget();
$WC_Widget->update( $new_instance, $old_instance );
$new_instance(array) (required)
New instance.
$old_instance(array) (required)
Old instance.

Notes

  • See: WP_Widget->update

Code of WC_Widget::update() WC 5.8.0

public function update( $new_instance, $old_instance ) {

	$instance = $old_instance;

	if ( empty( $this->settings ) ) {
		return $instance;
	}

	// Loop settings and get values to save.
	foreach ( $this->settings as $key => $setting ) {
		if ( ! isset( $setting['type'] ) ) {
			continue;
		}

		// Format the value based on settings type.
		switch ( $setting['type'] ) {
			case 'number':
				$instance[ $key ] = absint( $new_instance[ $key ] );

				if ( isset( $setting['min'] ) && '' !== $setting['min'] ) {
					$instance[ $key ] = max( $instance[ $key ], $setting['min'] );
				}

				if ( isset( $setting['max'] ) && '' !== $setting['max'] ) {
					$instance[ $key ] = min( $instance[ $key ], $setting['max'] );
				}
				break;
			case 'textarea':
				$instance[ $key ] = wp_kses( trim( wp_unslash( $new_instance[ $key ] ) ), wp_kses_allowed_html( 'post' ) );
				break;
			case 'checkbox':
				$instance[ $key ] = empty( $new_instance[ $key ] ) ? 0 : 1;
				break;
			default:
				$instance[ $key ] = isset( $new_instance[ $key ] ) ? sanitize_text_field( $new_instance[ $key ] ) : $setting['std'];
				break;
		}

		/**
		 * Sanitize the value of a setting.
		 */
		$instance[ $key ] = apply_filters( 'woocommerce_widget_settings_sanitize_option', $instance[ $key ], $new_instance, $key, $setting );
	}

	$this->flush_widget_cache();

	return $instance;
}