Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active February 4, 2020 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spivurno/ae0eb2eb8bad99e841f4 to your computer and use it in GitHub Desktop.
Save spivurno/ae0eb2eb8bad99e841f4 to your computer and use it in GitHub Desktop.
GP Unique ID // Gravity Perks // Populate Unique ID via Dynamic Population
<?php
/**
* GP Unique ID // Gravity Perks // Populate Unique ID via Dynamic Population
*
* INSTRUCTIONS:
*
* 1 - Copy and paste this code into your theme's functions.php file.
* 2 - Add a Single Line Text field (or any field you would like to populate with a unique ID) to your form.
* 3 - Enable the "Allow field to be populated dynamically" setting under the Advanced tab on the field settings for the newly created field.
* 4 - Set "uid" as the value for the Paramater Name setting (screenshot: https://gwiz.io/2HhtBTa).
*/
add_filter( 'gform_field_value_uid', function( $value, $field ) {
if( function_exists( 'gp_unique_id' ) ) {
$field[ gp_unique_id()->perk->key( 'length' ) ] = 9;
$value = gp_unique_id()->get_unique( $field->formId, $field );
}
return $value;
}, 10, 2 );
@ImChefMike
Copy link

Where would I put this? In my functions.php or just upload it to my Plugins folder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment