_acf_get_seamless_clone_path() │ ACF 6.8.11

Returns the sub field keys from a seamless clone down to one of its (possibly nested) sub fields.

acf_get_fields() flattens seamless clones of seamless clones to their innermost fields; this finds the intermediate clones between the outer clone and such a field.

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

array. The keys from the clone's direct sub field to the field, or an empty array if not found.

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

_acf_get_seamless_clone_path( $clone_field, $key );
$clone_field(массив) (обязательный)
The clone field.
$key(строка) (обязательный)
The sub field's key.

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

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

Код _acf_get_seamless_clone_path() ACF 6.8.11

function _acf_get_seamless_clone_path( $clone_field, $key ) {
	foreach ( (array) ( $clone_field['sub_fields'] ?? array() ) as $sub_field ) {
		if ( ( $sub_field['key'] ?? '' ) === $key ) {
			return array( $key );
		}

		if ( 'clone' === ( $sub_field['type'] ?? '' ) && 'seamless' === ( $sub_field['display'] ?? '' ) ) {
			$path = _acf_get_seamless_clone_path( $sub_field, $key );

			if ( $path ) {
				return array_merge( array( $sub_field['key'] ), $path );
			}
		}
	}

	return array();
}