acf_duplicate_fields()ACF 5.0.0

acf_duplicate_fields

Duplicate an array of fields.

Хуков нет.

Возвращает

Массив.

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

acf_duplicate_fields( $fields, $parent_id );
$fields(массив)
An array of fields.
По умолчанию: array()
$parent_id(int)
The new parent ID.

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

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

Код acf_duplicate_fields() ACF 5.10.2

function acf_duplicate_fields( $fields = array(), $parent_id = 0 ) {

	// Generate keys for all new fields
	// - Needed to alter conditional logic rules
	// - Use usleep() to ensure unique keys.
	$keys = array();
	foreach ( $fields as $field ) {
		usleep( 1 );
		$keys[ $field['key'] ] = uniqid( 'field_' );
	}
	acf_append_data( 'generated_keys', $keys );

	// Duplicate fields.
	foreach ( $fields as $field ) {
		$field_id     = $field['ID'] ? $field['ID'] : $field['key'];
		$duplicates[] = acf_duplicate_field( $field_id, $parent_id );
	}

	// Return.
	return $duplicates;
}