Force Dynamic Population When Editing Entry.

Use this snippet to force fields to be dynamically repopulated via Populate Anything when they are edited via the Gravity Forms edit entry screen.

Instructions

Code

Filename: gppa-force-lmt-populate-on-edit.php

<?php
/**
 * Gravity Forms // Populate Anything // Force Dynamic Population When Editing Entry.
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * Instruction Video: https://www.loom.com/share/6a7f28fc0cde406798d5bad4b386a70a
 *
 * Use this snippet to force fields to be dynamically repopulated via Populate Anything when they are
 * edited via the Gravity Forms edit entry screen.
 */
add_action( 'gform_after_update_entry', function ( $form, $entry_id ) {
	$gppa_lmt = GP_Populate_Anything_Live_Merge_Tags::get_instance();
	$entry    = GFAPI::get_entry( $entry_id );
	foreach ( $form['fields'] as $field ) {
		// For any field having Live Merge Tags.
		if ( $gppa_lmt->has_live_merge_tag( $field->defaultValue ) ) {
			$gppa_lmt->populate_lmt_whitelist( $form );
			remove_all_filters('gform_pre_replace_merge_tags');

			// Process the Live Merge Tags.
			$merge_tag = preg_replace( '/@(?=\{)/', '', $field->defaultValue );
			$value     = GFCommon::replace_variables( $merge_tag, $form, $entry );

			// Store updated value on the entry.
			GFFormsModel::update_entry_field_value( $form, $entry, $field, '', $field->id, $value );
		}
	}
}, 15, 2 );

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.