acf_field_checkbox::update_value()publicACF 3.6

This filter is appied to the $value before it is updated in the db

Метод класса: acf_field_checkbox{}

Хуков нет.

Возвращает

$value. - the modified value

Использование

$acf_field_checkbox = new acf_field_checkbox();
$acf_field_checkbox->update_value( $value, $post_id, $field );
$value (обязательный)
-
$post_id (обязательный)
-
$field (обязательный)
-

Список изменений

С версии 3.6 Введена.

Код acf_field_checkbox::update_value() ACF 6.0.4

function update_value( $value, $post_id, $field ) {

	// bail early if is empty
	if ( empty( $value ) ) {
		return $value;
	}

	// select -> update_value()
	$value = acf_get_field_type( 'select' )->update_value( $value, $post_id, $field );

	// save_other_choice
	if ( $field['save_custom'] ) {

		// get raw $field (may have been changed via repeater field)
		// if field is local, it won't have an ID
		$selector = $field['ID'] ? $field['ID'] : $field['key'];
		$field    = acf_get_field( $selector );
		if ( ! $field ) {
			return false;
		}

		// bail early if no ID (JSON only)
		if ( ! $field['ID'] ) {
			return $value;
		}

		// loop
		foreach ( $value as $v ) {

			// ignore if already eixsts
			if ( isset( $field['choices'][ $v ] ) ) {
				continue;
			}

			// unslash (fixes serialize single quote issue)
			$v = wp_unslash( $v );

			// sanitize (remove tags)
			$v = sanitize_text_field( $v );

			// append
			$field['choices'][ $v ] = $v;

		}

		// save
		acf_update_field( $field );

	}

	// return
	return $value;

}