Skip to content

Instantly share code, notes, and snippets.

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/91be22f6c6ca4ac4cfb104768b0694d2 to your computer and use it in GitHub Desktop.
Save spivurno/91be22f6c6ca4ac4cfb104768b0694d2 to your computer and use it in GitHub Desktop.
Gravity Perks // Populate Anything // Auto-update Form ID on Form Duplication
<?php
/**
* Gravity Perks // Populate Anything // Auto-update Form ID on Form Duplication
* http://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* When populating Gravity Forms Entries via Populate Anything, it can save time to automatically update the selected
* form ID to the new form ID when duplicating an existing form. To enable on any field, just set the
* "gppa-set-current-form" class on the CSS Class Name setting.
*/
add_action( 'gform_post_form_duplicated', function( $form_id, $new_id ) {
$form = GFAPI::get_form( $new_id );
$has_change = false;
foreach ( $form['fields'] as &$field ) {
if ( strpos( $field->cssClass, 'gppa-set-current-form' ) !== false ) {
$has_change = true;
$field->{'gppa-values-primary-property'} = $new_id;
}
}
if ( $has_change ) {
GFAPI::update_form( $form );
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment