Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created July 2, 2025 05:09
Show Gist options
  • Save rafaehlers/6476238dfbe1c6bd7c4fbf2583511b8f to your computer and use it in GitHub Desktop.
Save rafaehlers/6476238dfbe1c6bd7c4fbf2583511b8f to your computer and use it in GitHub Desktop.
Merge Tag modifier to output file upload links with filenames
<?php // DO NOT COPY THIS LINE
add_filter( 'gform_secure_file_download_location', '__return_false' );
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value ) {
if ( 'all_fields' !== $merge_tag && 'linker' === $modifier ) {
// Split on <br> tags, line breaks, or commas
$files = preg_split('/<br\s*\/?>|\r\n|\r|\n|,/', trim($value));
$output = '';
foreach ( $files as $file_url ) {
$file_url = trim($file_url);
if( empty($file_url) ) {
continue;
}
$file_name = basename($file_url);
$output .= '<a href="'.$file_url.'" target="_blank">'.$file_name.'</a><br>';
}
// Remove trailing <br> if desired
$output = rtrim($output, '<br>');
return $output;
}
return $value;
}, 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment