Skip to content

Commit 4beb163

Browse files
authored
gppa-force-lmt-populate-on-edit.php: Added snippet to update Live Merge Tags when editing entries.
1 parent efab86e commit 4beb163

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Gravity Forms // Populate Anything // Force Dynamic Population When Editing Entry.
4+
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
5+
*
6+
* Instruction Video: https://www.loom.com/share/6a7f28fc0cde406798d5bad4b386a70a
7+
*
8+
* Use this snippet to force fields to be dynamically repopulated via Populate Anything when they are
9+
* edited via the Gravity Forms edit entry screen.
10+
*/
11+
add_action( 'gform_after_update_entry', function ( $form, $entry_id ) {
12+
$gppa_lmt = GP_Populate_Anything_Live_Merge_Tags::get_instance();
13+
$entry = GFAPI::get_entry( $entry_id );
14+
foreach ( $form['fields'] as $field ) {
15+
// For any field having Live Merge Tags.
16+
if ( $gppa_lmt->has_live_merge_tag( $field->defaultValue ) ) {
17+
$gppa_lmt->populate_lmt_whitelist( $form );
18+
remove_all_filters('gform_pre_replace_merge_tags');
19+
20+
// Process the Live Merge Tags.
21+
$merge_tag = preg_replace( '/@(?=\{)/', '', $field->defaultValue );
22+
$value = GFCommon::replace_variables( $merge_tag, $form, $entry );
23+
24+
// Store updated value on the entry.
25+
GFFormsModel::update_entry_field_value( $form, $entry, $field, '', $field->id, $value );
26+
}
27+
}
28+
}, 15, 2 );

0 commit comments

Comments
 (0)