acf_field_select::update_value
Filters the $value before it is updated in the db.
Метод класса: acf_field_select{}
Хуков нет.
Возвращает
Разное.
Использование
$acf_field_select = new acf_field_select(); $acf_field_select->update_value( $value, $post_id, $field );
- $value(разное) (обязательный)
- The value which will be saved in the database.
- $post_id(int|строка) (обязательный)
- The post_id of which the value will be saved.
- $field(массив) (обязательный)
- The field array holding all the field options.
Список изменений
| С версии 3.6 | Введена. |
Код acf_field_select::update_value() acf field select::update value ACF 6.4.2
public function update_value( $value, $post_id, $field ) {
// Bail early if no value.
if ( empty( $value ) ) {
return $value;
}
// Format array of values.
// - Parse each value as string for SQL LIKE queries.
if ( is_array( $value ) ) {
$value = array_map( 'strval', $value );
}
// Save custom options back to the field definition if configured.
if ( ! empty( $field['save_options'] ) && is_array( $value ) ) {
// Get the raw field, using the ID if present or the key otherwise (i.e. when using JSON).
$selector = $field['ID'] ? $field['ID'] : $field['key'];
$field = acf_get_field( $selector );
// Bail if we don't have a valid field or field ID (JSON only).
if ( empty( $field['ID'] ) ) {
return $value;
}
foreach ( $value as $v ) {
// Ignore if the option already exists.
if ( isset( $field['choices'][ $v ] ) ) {
continue;
}
// Unslash (fixes serialize single quote issue) and sanitize.
$v = wp_unslash( $v );
$v = sanitize_text_field( $v );
// Append to the field choices.
$field['choices'][ $v ] = $v;
}
acf_update_field( $field );
}
return $value;
}