acf_field_repeater::get_field_name_from_input_name()publicACF 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.

Метод класса: acf_field_repeater{}

Хуков нет.

Возвращает

Строку|true|false.

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

$acf_field_repeater = new acf_field_repeater();
$acf_field_repeater->get_field_name_from_input_name( $input_name );
$input_name(строка) (обязательный)
The name attribute used in the repeater.

Код acf_field_repeater::get_field_name_from_input_name() ACF 6.0.4

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

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

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

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

			$row_num = str_replace( 'row-', '', $field_key );
			if ( is_numeric( $row_num ) ) {
				$name_parts[] = (int) $row_num;
				continue;
			}
		}

		$field = acf_get_field( $field_key );

		if ( $field ) {
			$name_parts[] = $field['name'];
		}
	}

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