acf_field_flexible_content::update_row
This function will update a value row
Метод класса: acf_field_flexible_content{}
Хуков нет.
Возвращает
true|false.
Использование
$acf_field_flexible_content = new acf_field_flexible_content(); $acf_field_flexible_content->update_row( $row, $i, $field, $post_id );
- $row(массив) (обязательный)
- .
- $i(int) (обязательный)
- .
- $field(массив) (обязательный)
- .
- $post_id(разное) (обязательный)
- .
Список изменений
| С версии 5.5.8 | Введена. |
Код acf_field_flexible_content::update_row() acf field flexible content::update row ACF 6.4.2
public function update_row( $row, $i, $field, $post_id ) {
// bail early if no layout reference
if ( ! is_array( $row ) || ! isset( $row['acf_fc_layout'] ) ) {
return false;
}
// get layout
$layout = $this->get_layout( $row['acf_fc_layout'], $field );
// bail early if no layout
if ( ! $layout || empty( $layout['sub_fields'] ) ) {
return false;
}
foreach ( $layout['sub_fields'] as $sub_field ) {
$value = null;
if ( array_key_exists( $sub_field['key'], $row ) ) {
$value = $row[ $sub_field['key'] ];
} elseif ( array_key_exists( $sub_field['name'], $row ) ) {
$value = $row[ $sub_field['name'] ];
} else {
// Value does not exist.
continue;
}
// modify name for save
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// update field
acf_update_value( $value, $post_id, $sub_field );
}
return true;
}