acf_form_customizer::save_widget
This function will hook into the widget update filter and save ACF data
Метод класса: acf_form_customizer{}
Хуков нет.
Возвращает
$instance.
Использование
$acf_form_customizer = new acf_form_customizer(); $acf_form_customizer->save_widget( $instance, $new_instance, $old_instance, $widget );
- $instance(обязательный)
- .
- $new_instance(обязательный)
- .
- $old_instance(обязательный)
- .
- $widget(обязательный)
- .
Список изменений
| С версии 5.2.3 | Введена. |
Код acf_form_customizer::save_widget() acf form customizer::save widget ACF 6.8.11
function save_widget( $instance, $new_instance, $old_instance, $widget ) {
// The field lists are kept in the instance's ACF data instead.
unset( $instance['_acf_fields'] );
// bail early if not valid (customize + acf values + nonce)
if ( ! isset( $_POST['wp_customize'] ) || ! isset( $new_instance['acf'] ) || ! acf_verify_nonce( 'widget' ) ) {
return $instance;
}
// vars
$data = array(
'post_id' => "widget_{$widget->id}",
'values' => array(),
'fields' => array(),
'_acf_fields' => array(),
);
// Only keep fields rendered for the widget, or that apply to it. The lists are kept so customize_save() can check again.
$data['_acf_fields'] = isset( $new_instance['_acf_fields'] ) && is_array( $new_instance['_acf_fields'] ) ? $new_instance['_acf_fields'] : array();
$data['values'] = acf_get_instance( 'acf_form_widget' )->filter_values( $new_instance['acf'], $data['_acf_fields'], $widget->id_base, $data['post_id'] );
// append fields (name => key relationship) - used later in 'acf/get_field_reference' for customizer previews
foreach ( $data['values'] as $k => $v ) {
// get field
$field = acf_get_field( $k );
// continue if no field
if ( ! $field ) {
continue;
}
// update
$data['fields'][ $field['name'] ] = $field['key'];
}
// append data to instance
$instance['acf'] = $data;
// return
return $instance;
}