Skip to content

Commit 2e5d3f7

Browse files
committed
gpui-sequential-ids-as-per-date-field.php: Added snippet to generate Unique IDs as per selected date field.
1 parent 6dac47d commit 2e5d3f7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* GP Unique ID // Gravity Perks // Creates Sequential IDs as per Date Field selected.
4+
* http://gravitywiz.com/
5+
*
6+
* Make the sequence for a given Unique ID field specific to the date field value. The sequence will automatically
7+
* generate Unique IDs for a particular date.
8+
*/
9+
// Update "123" to your form ID and "4" to your Unique ID field.
10+
add_filter( 'gpui_unique_id_attributes_123_4', 'gw_generate_unique_id_as_per_date_field', 10, 4);
11+
function gw_generate_unique_id_as_per_date_field( $atts, $entry, $form_id, $field_id ) {
12+
// Replace 4 with the Date field ID used for targetting Unique ID generation
13+
$date_field_id = 4;
14+
15+
// Remove any special character like / - . which can be in the date field value.
16+
$date_string = str_replace( array( '/', '-', '.' ), '', $entry[$date_field_id] );
17+
18+
// Update UID Attributes with the date string.
19+
$atts['form_id'] = (int) $date_string;
20+
21+
return $atts;
22+
}

0 commit comments

Comments
 (0)