Skip to content

Commit 99b672c

Browse files
authored
gpdtc-recalc.php: Fixed an issue with the snippet causing infinite recursion.
1 parent cb06fa4 commit 99b672c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

gp-date-time-calculator/gpdtc-recalc.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@
1616
$form_id = 123; // Change this to the form's ID
1717
$field_id = 4; // Change this to the Calculation field's ID.
1818

19-
$values = array();
19+
$values = array();
20+
$calculating = false;
2021

21-
add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values ) {
22-
if ( $field['id'] !== $field_id ) {
22+
add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values, $calculating ) {
23+
if ( $calculating || $field['id'] !== $field_id ) {
2324
$values[ $field['id'] ] = $value;
2425
return $value;
2526
}
27+
28+
// Set flag to prevent infinite recursion.
29+
$calculating = true;
30+
2631
$form = GFAPI::get_form( $entry['form_id'] );
2732
$_entry = $entry + $values;
33+
34+
// Reset flag.
35+
$calculating = false;
36+
2837
return GFCommon::calculate( $field, $form, $_entry );
2938
}, 10, 4 );
3039

0 commit comments

Comments
 (0)