acf_field_checkbox::update_value() public ACF 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) (обязательный)
- the value which will be saved in the database
-
- ($post_id) (обязательный)
- the $post_id of which the value will be saved
-
- ($field) (обязательный)
- the field array holding all the field options
Список изменений
С версии 3.6 | Введена. |
Код acf_field_checkbox::update_value() acf field checkbox::update value ACF 5.9.1
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;
}