Skip to content

Commit fcf3ea9

Browse files
authored
gpls-skip-limit-if-blank.php: Added new snippet for skipping limit if any Field Value is blank.
1 parent c8ed9f2 commit fcf3ea9

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Limit Submissions // Skip Limit If Any Field Value Is Blank
4+
* https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
5+
*
6+
* Skip evaluation of Limit Submissions feed whenever one of its field-based rules
7+
* resolves to a blank value for the current submission.
8+
*/
9+
add_filter( 'gpls_should_apply_rules', function( $should_apply, $form_id, $rule_test ) {
10+
11+
if ( ! $should_apply || empty( $rule_test->rules ) || empty( $rule_test->rule_group ) ) {
12+
return $should_apply;
13+
}
14+
15+
// Replace '123' with your Form ID
16+
$target_form_ids = array( 123 );
17+
18+
if ( ! in_array( (int) $form_id, $target_form_ids, true ) ) {
19+
return $should_apply;
20+
}
21+
22+
$feed_id = method_exists( $rule_test->rule_group, 'get_feed_id' ) ? $rule_test->rule_group->get_feed_id() : null;
23+
24+
if ( $feed_id && ! empty( $rule_test->skip_limit_feed_on_blank ) ) {
25+
return false;
26+
}
27+
28+
foreach ( $rule_test->rules as $rule ) {
29+
if ( ! $rule instanceof GPLS_Rule_Field ) {
30+
continue;
31+
}
32+
33+
$value = $rule->get_limit_field_value( $rule->get_field() );
34+
35+
if ( false === $value ) {
36+
continue;
37+
}
38+
39+
if ( is_array( $value ) ) {
40+
$value = GFCommon::trim_deep( $value );
41+
42+
if ( GFCommon::is_empty_array( $value ) ) {
43+
$rule_test->skip_limit_feed_on_blank = true;
44+
return false;
45+
}
46+
47+
continue;
48+
}
49+
50+
if ( is_string( $value ) ) {
51+
$value = trim( $value );
52+
}
53+
54+
if ( rgblank( $value ) ) {
55+
$rule_test->skip_limit_feed_on_blank = true;
56+
return false;
57+
}
58+
}
59+
60+
return $should_apply;
61+
}, 20, 3 );

0 commit comments

Comments
 (0)