Last active
September 2, 2020 02:53
-
-
Save spivurno/b25723b0f17c1bd28ab6c5e9100fc506 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Unique ID // HyperDB Support for Sequential IDs
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 | |
/** | |
* Gravity Perks // GP Unique ID // HyperDB Support for Sequential IDs | |
* http://gravitywiz.com/documentation/gravity-forms-unique-id/ | |
*/ | |
add_filter( 'gpui_sequential_unique_id_pre_insert', function( $uid, $form_id, $field_id, $starting_number) { | |
global $wpdb; | |
$wpdb->query( 'START TRANSACTION' ); | |
$sql = $wpdb->prepare( | |
'INSERT INTO ' . $wpdb->prefix . 'gpui_sequence ( form_id, field_id, current ) VALUES ( %d, %d, ( @next := 1 ) ) ON DUPLICATE KEY UPDATE current = ( @next := current + 1 )', | |
$form_id, $field_id | |
); | |
$wpdb->query( $sql ); | |
$uid = $wpdb->get_var( $wpdb->prepare( 'SELECT `current` from ' . $wpdb->prefix . 'gpui_sequence where form_id = %d and field_id = %d', $form_id, $field_id ) ); | |
$wpdb->query( 'COMMIT' ); | |
return $uid; | |
}, 10, 5 ); |
Thanks for the update!
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-unique-id/gpuid-hyperdb.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works Thanks !
But I think line 17 should be updated to
to work in multisite as we aren't statically calling
wp_gpui_sequence
in the query.