Last active
February 4, 2020 21:59
-
-
Save spivurno/ae0eb2eb8bad99e841f4 to your computer and use it in GitHub Desktop.
GP Unique ID // Gravity Perks // Populate Unique ID via Dynamic Population
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where would I put this? In my functions.php or just upload it to my Plugins folder?