WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

acf_duplicate_field() ACF 5.0.0

Duplicates a field.

Хуки из функции
Возвращает

true|false. True if field was duplicated.

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

acf_duplicate_field( $id, $parent_id );
$id((int|строка))
The field ID, key or name.
$parent_id(int)
The new parent ID.

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

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

Код acf_duplicate_field() ACF 5.9.1

<?php
function acf_duplicate_field( $id = 0, $parent_id = 0 ){
	
	// Get the field.
	$field = acf_get_field( $id );
	
	// Bail early if field was not found.
	if( !$field ) {
		return false;
	}
	
	// Remove ID to avoid update.
	$field['ID'] = 0;
	
	// Generate key.
	$keys = acf_get_data( 'generated_keys' );
	if( isset( $keys[ $field['key'] ] ) ) {
		$field['key'] = $keys[ $field['key'] ];
	} else {
		$field['key'] = uniqid('field_');
	}
	
	// Set parent.
	if( $parent_id ) {
		$field['parent'] = $parent_id;
	}
	
	// Update conditional logic references because field keys have changed.
	if( $field['conditional_logic'] ) {
		
		// Loop over groups
		foreach( $field['conditional_logic'] as $group_i => $group ) {
			
			// Loop over rules
			foreach( $group as $rule_i => $rule ) {
				$field['conditional_logic'][ $group_i ][ $rule_i ]['field'] = isset($keys[ $rule['field'] ]) ? $keys[ $rule['field'] ] : $rule['field'];
			}
		}
	}
	
	/**
	 * Filters the $field array after it has been duplicated.
	 *
	 * @date	12/02/2014
	 * @since	5.0.0
	 *
	 * @param	array $field The field array.
	 */
	$field = apply_filters( "acf/duplicate_field", $field);
	
	// Update and return.
	return acf_update_field( $field );
}