Skip to content

Commit 1de825a

Browse files
committed
gw-custom-modifier-file-upload.php: Added snippet for custom filename modifier for file upload fields.
1 parent 453ad6a commit 1de825a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Gravity Wizards // Gravity Forms // Custom Modifier for File Upload
4+
*
5+
* This snippet is an example of how to add custom modifiers to a Gravity Forms file upload field.
6+
*
7+
* Instructions:
8+
*
9+
* 1. Add to snippet to site. See https://gravitywiz.com/documentation/how-do-i-install-a-snippet/.
10+
*/
11+
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) {
12+
if ( $merge_tag != 'all_fields' && $field->type == 'fileupload' && ! empty( $raw_value ) && $modifier == 'filename' ) {
13+
if ( ! $field->multipleFiles ) {
14+
$value = basename( $raw_value );
15+
} else {
16+
$file_list = [];
17+
foreach ( json_decode( $raw_value ) as $filepath ) {
18+
$file_list[] = basename( $filepath );
19+
}
20+
$value = implode( '<br />', $file_list );
21+
}
22+
}
23+
return $value;
24+
}, 10, 6 );
25+
26+
// For GP Media Library
27+
add_filter( 'gpml_image_merge_tag_skip_modifiers', function( $skip_modifiers, $modifiers, $input_id, $image_ids ) {
28+
return [ 'filename' ];
29+
}, 10, 4 );

0 commit comments

Comments
 (0)