acf_field_radio::update_value │ public │ ACF 3.6

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

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

Возвращает

$value. - the modified value

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

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

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

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

Код acf_field_radio::update_value() ACF 6.8.11

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

	// bail early if no value (allow 0 to be saved)
	if ( ! $value && ! is_numeric( $value ) ) {
		return $value;
	}

	// bail early if not saving other choices, or the value is already a choice
	if ( ! $field['save_other_choice'] || isset( $field['choices'][ $value ] ) ) {
		return $value;
	}

	// 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 );

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

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

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

	/** This filter is documented in includes/fields/class-acf-field-select.php */
	if ( ! apply_filters( 'acf/fields/allow_append_choices', true, $field, $post_id ) ) {
		return $value;
	}

	/** This filter is documented in includes/fields/class-acf-field-select.php */
	$max = (int) apply_filters( 'acf/fields/max_appended_choices', 1000, $field, $post_id );

	// bail if the cap is reached; the normalized value still saves
	if ( count( $field['choices'] ) >= $max ) {
		return $value;
	}

	// update $field
	$field['choices'][ $value ] = $value;

	// save, see acf_field_select::append_user_choices_to_field() for why
	acf_skip_internal_post_sanitization( 'acf_update_field', wp_slash( $field ) );

	// return
	return $value;
}