acf_field_clone::format_value_for_rest()publicACF 1.0

Apply basic formatting to prepare the value for default REST output.

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

Хуков нет.

Возвращает

Разное.

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

$acf_field_clone = new acf_field_clone();
$acf_field_clone->format_value_for_rest( $value, $post_id, $field );
$value(разное) (обязательный)
-
$post_id(строка|int) (обязательный)
-
$field(массив) (обязательный)
-

Код acf_field_clone::format_value_for_rest() ACF 6.0.4

public function format_value_for_rest( $value, $post_id, array $field ) {
	if ( empty( $value ) || ! is_array( $value ) ) {
		return $value;
	}

	if ( ! is_array( $field ) || ! isset( $field['sub_fields'] ) || ! is_array( $field['sub_fields'] ) ) {
		return $value;
	}

	// Loop through each row and within that, each sub field to process sub fields individually.
	foreach ( $field['sub_fields'] as $sub_field ) {

		// Extract the sub field 'field_key'=>'value' pair from the $value and format it.
		$sub_value = acf_extract_var( $value, $sub_field['key'] );
		$sub_value = acf_format_value_for_rest( $sub_value, $post_id, $sub_field );

		// Add the sub field value back to the $value but mapped to the field name instead
		// of the key reference.
		$value[ $sub_field['name'] ] = $sub_value;
	}

	return $value;
}