Skip to content

Commit 083d492

Browse files
committed
gpdtc-recalc.php: Added GravityView Support.
1 parent 73f2cdd commit 083d492

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
$field_id = 4; // Change this to the Calculation field's ID.
1818

1919
$values = array();
20-
$calculating = false;
20+
$calculating = false; // Flag to prevent infinite recursion
2121

22-
add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values, $calculating ) {
22+
add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values, &$calculating ) {
23+
// Prevent infinite recursion
2324
if ( $calculating ) {
2425
return $value;
2526
}
@@ -29,16 +30,15 @@
2930
return $value;
3031
}
3132

32-
// Set flag to prevent infinite recursion.
33+
// Set flag to prevent recursion
3334
$calculating = true;
3435

35-
$form = GFAPI::get_form( $entry['form_id'] );
36-
$_entry = $entry + $values;
36+
$form = GFAPI::get_form( $entry['form_id'] );
37+
$_entry = $entry + $values;
3738
$calculated_value = GFCommon::calculate( $field, $form, $_entry );
3839

3940
GFAPI::update_entry_field( $_entry['id'], $field_id, $calculated_value );
40-
41-
// Reset flag.
41+
// Reset flag
4242
$calculating = false;
4343

4444
return $calculated_value;
@@ -49,7 +49,6 @@
4949
if ( $field->ID != $field_id && $form->ID != $form_id ) {
5050
return $value;
5151
}
52-
5352
$orig_entry = GFAPI::get_entry( $entry->ID );
5453
return rgar( $orig_entry, $field_id );
5554
}, 10, 5 );

0 commit comments

Comments
 (0)