acf_field_flexible_content::prepare_field_for_import()publicACF 5.0.0

prepare_field_for_import

description

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

Хуков нет.

Возвращает

$post_id. (int)

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

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

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

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

Код acf_field_flexible_content::prepare_field_for_import() ACF 6.0.4

function prepare_field_for_import( $field ) {

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

	// Storage for extracted fields.
	$extra = array();

	// Loop over layouts.
	foreach ( $field['layouts'] as &$layout ) {

		// Ensure layout is valid.
		$layout = $this->get_valid_layout( $layout );

		// Extract sub fields.
		$sub_fields = acf_extract_var( $layout, 'sub_fields' );

		// Modify and append sub fields to $extra.
		if ( $sub_fields ) {
			foreach ( $sub_fields as $i => $sub_field ) {

				// Update atttibutes
				$sub_field['parent']        = $field['key'];
				$sub_field['parent_layout'] = $layout['key'];
				$sub_field['menu_order']    = $i;

				// Append to extra.
				$extra[] = $sub_field;
			}
		}
	}

	// Merge extra sub fields.
	if ( $extra ) {
		array_unshift( $extra, $field );
		return $extra;
	}

	// Return field.
	return $field;
}