Skip to content

Commit ac13a44

Browse files
authored
Update gpdtc-calculated-input-value.php
1 parent 0c23a04 commit ac13a44

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed
Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,6 @@
11
<?php
22
/**
3-
* Calculate input values after submission to ensure that calculated values are always up-to-date.
4-
*
5-
* Works great with Date Time Calculator's :age modifier.
6-
* https://gravitywiz.com/documentation/gravity-forms-date-time-calculator/#calculating-age
3+
* This snippet has evolved! 🦄
4+
* Find the new version of this snippet here:
5+
* https://github.com/gravitywiz/snippet-library/blob/master/experimental/gpdtc-recalc.php
76
*/
8-
class GW_Calculated_Input_Value {
9-
protected $_args;
10-
11-
function __construct( $args ) {
12-
$this->_args = wp_parse_args( $args );
13-
14-
$this->add_hook();
15-
}
16-
17-
function get_filter_tag() {
18-
return sprintf( 'gform_get_input_value_%d_%d', $this->_args['form_id'], $this->_args['field_id'] );
19-
}
20-
21-
function add_hook() {
22-
add_filter( $this->get_filter_tag(), array( $this, 'calculate_field' ), 10, 4 );
23-
}
24-
25-
function remove_hook() {
26-
remove_filter( $this->get_filter_tag(), array( $this, 'calculate_field' ) );
27-
}
28-
29-
function calculate_field( $value, $entry, $field, $input_id ) {
30-
$this->remove_hook(); // Prevent recursion
31-
$form = GFAPI::get_form( $entry['form_id'] );
32-
$entry = GFAPI::get_entry( $entry['id'] );
33-
$this->add_hook();
34-
35-
if ( ! $form || ! $entry ) {
36-
return $value;
37-
}
38-
39-
return GFCommon::calculate( $field, $form, $entry );
40-
}
41-
}
42-
43-
new GW_Calculated_Input_Value( array(
44-
'form_id' => 413,
45-
'field_id' => 132,
46-
) );

0 commit comments

Comments
 (0)