Last active
October 7, 2021 15:11
-
-
Save spivurno/91be22f6c6ca4ac4cfb104768b0694d2 to your computer and use it in GitHub Desktop.
Gravity Perks // Populate Anything // Auto-update Form ID on Form Duplication
This file contains 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 // 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
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-populate-anything/gppa-set-current-form-on-duplicate.php