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.4.2
function save_widget( $instance, $new_instance, $old_instance, $widget ) {
// 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(),
);
// append values
$data['values'] = $new_instance['acf'];
// 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;
}