acf_field_clone::get_cloned_fields()publicACF 5.3.8

get_cloned_fields

This function will return an array of fields for a given clone field

@type    function

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

Хуков нет.

Возвращает

(Массив).

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

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

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

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

Код acf_field_clone::get_cloned_fields() ACF 5.10.2

function get_cloned_fields( $field ) {

	// vars
	$fields = array();

	// bail early if no clone setting
	if ( empty( $field['clone'] ) ) {
		return $fields;
	}

	// bail ealry if already cloning this field (avoid infinite looping)
	if ( isset( $this->cloning[ $field['key'] ] ) ) {
		return $fields;
	}

	// update local ref
	$this->cloning[ $field['key'] ] = 1;

	// Loop over selectors and load fields.
	foreach ( $field['clone'] as $selector ) {

		// Field Group selector.
		if ( acf_is_field_group_key( $selector ) ) {

			$field_group = acf_get_field_group( $selector );
			if ( ! $field_group ) {
				continue;
			}

			$field_group_fields = acf_get_fields( $field_group );
			if ( ! $field_group_fields ) {
				continue;
			}

			$fields = array_merge( $fields, $field_group_fields );

			// Field selector.
		} elseif ( acf_is_field_key( $selector ) ) {
			$fields[] = acf_get_field( $selector );
		}
	}

	// field has ve been loaded for this $parent, time to remove cloning ref
	unset( $this->cloning[ $field['key'] ] );

	// clear false values (fields that don't exist)
	$fields = array_filter( $fields );

	// bail early if no sub fields
	if ( empty( $fields ) ) {
		return array();
	}

	// loop
	// run acf_clone_field() on each cloned field to modify name, key, etc
	foreach ( array_keys( $fields ) as $i ) {

		$fields[ $i ] = acf_clone_field( $fields[ $i ], $field );

	}

	// return
	return $fields;

}