WC_Widget::update
Updates a particular instance of a widget.
Метод класса: WC_Widget{}
Хуки из метода
Возвращает
Массив.
Использование
$WC_Widget = new WC_Widget(); $WC_Widget->update( $new_instance, $old_instance );
- $new_instance(массив) (обязательный)
- New instance.
- $old_instance(массив) (обязательный)
- Old instance.
Заметки
- Смотрите: WP_Widget->update
Код WC_Widget::update() WC Widget::update WC 10.4.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;
}