Skip to content

Instantly share code, notes, and snippets.

@ano
Last active July 4, 2017 05:54
Show Gist options
  • Save ano/95f19663a9cf8126eca2009c970d7c24 to your computer and use it in GitHub Desktop.
Save ano/95f19663a9cf8126eca2009c970d7c24 to your computer and use it in GitHub Desktop.
Formidable Forms: Set Entry Key as UUID
<?php
/*
Plugin Name: Formidable Forms UUID
Plugin URI: https://gist.github.com/ano/95f19663a9cf8126eca2009c970d7c24
Description: Creates entry keys as UUIDv4 unique identifiers on form save.
Version: 1.0.0
Author: Ano Tisam
Author URI: https://www.linkedin.com/in/ano-tisam-19b50614/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Date: 7/4/2017
*/
/*
Change Entry Key to UUIDv4
*/
add_filter('frm_validate_entry', 'change_entry_key', 20, 2);
function change_entry_key($errors, $values){
if(($_POST['frm_action'] == 'create')){
$_POST['item_key'] = guidv4();
}
return $errors;
}
/*
Generate a version 4 UUID
*/
function guidv4()
{
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0010
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment