acf_form_customizer::save_widgetpublicACF 5.2.3

This function will hook into the widget update filter and save ACF data

Method of the class: acf_form_customizer{}

No Hooks.

Returns

$instance.

Usage

$acf_form_customizer = new acf_form_customizer();
$acf_form_customizer->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_customizer::save_widget() code ACF 6.8.8

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;
}