acf_form_widget::save_widget
This function will hook into the widget update filter and save ACF data
Метод класса: acf_form_widget{}
Хуков нет.
Возвращает
$instance.
Использование
$acf_form_widget = new acf_form_widget(); $acf_form_widget->save_widget( $instance, $new_instance, $old_instance, $widget );
- $instance(обязательный)
- .
- $new_instance(обязательный)
- .
- $old_instance(обязательный)
- .
- $widget(обязательный)
- .
Список изменений
| С версии 5.2.3 | Введена. |
Код acf_form_widget::save_widget() acf form widget::save widget ACF 6.8.11
function save_widget( $instance, $new_instance, $old_instance, $widget ) {
// The field lists are only needed to save the values, never in the stored instance.
unset( $instance['_acf_fields'] );
// validate nonce if we're not a REST API request.
// the $_POST object is not available to us to validate if we're in a REST API call.
if ( ! ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) ) {
if ( ! acf_verify_nonce( 'widget' ) ) {
return $instance;
}
}
// bail early if not valid (!customize + acf values + nonce).
if ( isset( $_POST['wp_customize'] ) || ! isset( $new_instance['acf'] ) ) {
return $instance;
}
// Widget values are saved from the instance, not $_FILES.
acf_discard_uploaded_field_values();
// save
acf_save_post( "widget_{$widget->id}", $this->filter_values( $new_instance['acf'], $new_instance['_acf_fields'] ?? array(), $widget->id_base, "widget_{$widget->id}" ) );
// return
return $instance;
}