acf_field_flexible_content::update_value()publicACF 3.6

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

@type filter

{} Это метод класса: acf_field_flexible_content{}

Хуков нет.

Возвращает

$value. - the modified value

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

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

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

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

Код acf_field_flexible_content::update_value() ACF 5.10.2

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

	// bail early if no layouts
	if ( empty( $field['layouts'] ) ) {
		return $value;
	}

	// vars
	$new_value = array();
	$old_value = acf_get_metadata( $post_id, $field['name'] );
	$old_value = is_array( $old_value ) ? $old_value : array();

	// update
	if ( ! empty( $value ) ) {
		$i = -1;

		// remove acfcloneindex
		if ( isset( $value['acfcloneindex'] ) ) {

			unset( $value['acfcloneindex'] );

		}

		// loop through rows
		foreach ( $value as $row ) {
			$i++;

			// bail early if no layout reference
			if ( ! is_array( $row ) || ! isset( $row['acf_fc_layout'] ) ) {
				continue;
			}

			// delete old row if layout has changed
			if ( isset( $old_value[ $i ] ) && $old_value[ $i ] !== $row['acf_fc_layout'] ) {

				$this->delete_row( $i, $field, $post_id );

			}

			// update row
			$this->update_row( $row, $i, $field, $post_id );

			// append to order
			$new_value[] = $row['acf_fc_layout'];

		}
	}

	// vars
	$old_count = empty( $old_value ) ? 0 : count( $old_value );
	$new_count = empty( $new_value ) ? 0 : count( $new_value );

	// remove old rows
	if ( $old_count > $new_count ) {

		// loop
		for ( $i = $new_count; $i < $old_count; $i++ ) {

			$this->delete_row( $i, $field, $post_id );

		}
	}

	// save false for empty value
	if ( empty( $new_value ) ) {
		$new_value = '';
	}

	// return
	return $new_value;

}