Gravity Wiz // GP Unique ID // Shared Sequences
<?php
/**
* WARNING! THIS SNIPPET MAY BE OUTDATED.
* The latest version of this snippet can be found in the Gravity Wiz Snippet Library:
* https://github.com/gravitywiz/snippet-library/blob/master/gp-unique-id/gpuid-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;
}