Generate New ID on Child Entry Duplication

Code

Filename: gpnf-gpuid-new-id-on-duplicate.php

<?php
/**
 * Gravity Perks // Nested Forms + Unique ID // Generate New ID on Child Entry Duplication
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 */
add_filter( 'gpnf_duplicate_entry', function( $entry ) {
	if ( ! is_callable( 'gp_unique_id' ) ) {
		return $entry;
	}
	$form = GFAPI::get_form( $entry['form_id'] );
	foreach ( $form['fields'] as $field ) {
		if ( is_a( $field, 'GF_Field_Unique_ID' ) ) {
			$entry[ $field->id ] = gp_unique_id()->get_unique( $form['id'], $field );
		}
	}
	return $entry;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.