spivurno
7/28/2016 - 9:38 PM

Gravity Wiz // GP Unique ID // Shared Sequences

Gravity Wiz // GP Unique ID // Shared Sequences

<?php
/**
 * Gravity Wiz // GP Unique ID // Shared Sequences
 * http://gravitywiz.com/
 * 
 * Share sequences between sequential Unique ID fields; works with fields on 
 * different forms as well.
 */
add_filter( 'gpui_unique_id_attributes', 'gwiz_unique_id_global_sequential_index', 10, 3 );
function gwiz_unique_id_global_sequential_index( $atts, $form_id, $field_id ) {

	$groups = array(
		array(
			519  => 3,
			1410 => 1
		),
		array(
			1 => 2,
			2 => 4
		)
	);

	if( $atts['type'] != 'sequential' ) {
		return $atts;
	}

	$group_number = false;

	foreach( $groups as $index => $group ) {
		foreach( $group as $_form_id => $_field_id ) {
			if( $_form_id == $form_id && $_field_id == $field_id ) {
				$group_number = $index + 1;
				break;
			}
		}
	}

	if( $group_number === false ) {
		return $atts;
	}

	$atts['starting_number'] = 1;
	$atts['form_id'] = 0;
	$atts['field_id'] = $group_number;

	return $atts;
}