acf_form_widget::save_widget
save_widget
This function will hook into the widget update filter and save ACF data
Method of the class: acf_form_widget{}
No Hooks.
Returns
$instance.
Usage
$acf_form_widget = new acf_form_widget(); $acf_form_widget->save_widget( $instance, $new_instance, $old_instance, $widget );
- $instance(required)
- .
- $new_instance(required)
- .
- $old_instance(required)
- .
- $widget(required)
- .
Changelog
| Since 5.2.3 | Introduced. |
acf_form_widget::save_widget() acf form widget::save widget code ACF 6.0.4
function save_widget( $instance, $new_instance, $old_instance, $widget ) {
// 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;
}
// save
acf_save_post( "widget_{$widget->id}", $new_instance['acf'] );
// return
return $instance;
}