acf_field_repeater::get_field_name_from_input_namepublicACF 1.0

Takes the provided input name and turns it into a field name that works with repeater fields that are subfields of other fields.

Method of the class: acf_field_repeater{}

No Hooks.

Returns

String|true|false.

Usage

$acf_field_repeater = new acf_field_repeater();
$acf_field_repeater->get_field_name_from_input_name( $input_name );
$input_name(string) (required)
The name attribute used in the repeater.

acf_field_repeater::get_field_name_from_input_name() code ACF 6.8.8

public function get_field_name_from_input_name( $input_name ) {
	$parts = array();
	preg_match_all( '/\[([^\]]*)\]/', is_null( $input_name ) ? '' : $input_name, $parts );

	if ( ! isset( $parts[1] ) ) {
		return false;
	}

	$field_keys = $parts[1];
	$name_parts = array();

	foreach ( $field_keys as $field_key ) {
		// Preserve acfcloneindex
		if ( $field_key === 'acfcloneindex' ) {
			$name_parts[] = 'acfcloneindex';
			continue;
		}

		// Handle row numbers (row-0, row-1, etc.)
		if ( strpos( $field_key, 'row-' ) === 0 ) {
			$row_num = substr( $field_key, 4 );
			if ( is_numeric( $row_num ) ) {
				$name_parts[] = (int) $row_num;
				continue;
			}
		}

		// Handle compound keys (field_..._field_...)
		$compound_keys = preg_split( '/_field_/', $field_key );
		if ( count( $compound_keys ) > 1 ) {
			foreach ( $compound_keys as $i => $sub_key ) {
				if ( $i > 0 ) {
					$sub_key = 'field_' . $sub_key;
				}

				// Seamless clone fields use compound keys which can be skipped.
				$field = acf_get_field( $sub_key );
				if ( $field && 'clone' === $field['type'] && 'seamless' === $field['display'] ) {
					continue;
				}

				$name_parts[] = $field && ! empty( $field['name'] ) ? $field['name'] : $sub_key;
			}
			continue;
		}

		// Handle standard field keys
		if ( strpos( $field_key, 'field_' ) === 0 ) {

			// Skip clone fields with prefix_name disabled.
			$field = acf_get_field( $field_key );
			if ( $field && $field['type'] === 'clone' && empty( $field['prefix_name'] ) ) {
				continue;
			}

			$name_parts[] = $field && ! empty( $field['name'] ) ? $field['name'] : $field_key;
			continue;
		}

		// Fallback: just add as is
		$name_parts[] = $field_key;
	}

	return implode( '_', $name_parts );
}