Skip to content

Commit 45ab4d6

Browse files
authored
gptos-terms-only-modifier.php: Added snippet to only display terms with the TOS checkbox.
1 parent 183e85f commit 45ab4d6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Terms of Service // Add a `:terms_only` modifier.
4+
* https://gravitywiz.com/documentation/gravity-forms-terms-of-service/
5+
*
6+
* Add a `:terms_only` modifier to the {all_fields} merge tag to only display the terms.
7+
*
8+
* Instruction Video: https://www.loom.com/share/d69c48bea2d1429ab019310d2bc6c1e6
9+
*/
10+
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $options, $field ) {
11+
if ( $field['type'] !== 'tos' ) {
12+
return $value;
13+
}
14+
15+
$options = explode( ',', $options );
16+
if ( ! in_array( 'terms_only', $options ) ) {
17+
return $value;
18+
}
19+
20+
if ( $merge_tag !== 'all_fields' ) {
21+
$value = '<ul><li>' . $value . '</li></ul>';
22+
}
23+
24+
$value = wpautop( $field->get_terms( GFAPI::get_form( $field->formId ) ) );
25+
26+
return $value;
27+
}, 11, 4 );

0 commit comments

Comments
 (0)