Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcat-support/d0b817a4270c302d6325d76b0b67d017 to your computer and use it in GitHub Desktop.
Save vcat-support/d0b817a4270c302d6325d76b0b67d017 to your computer and use it in GitHub Desktop.
Example on how to change the file name of the zip archive.
<?php
/**
* Plugin Name: Bulk Download for Gravity Forms - Change zip file name.
* Description: Example on how to change the file name of the zip archive.
* Author: VCAT Consulting GmbH
* Author URI: https://www.vcat.de
*/
/**
* Filter the file name of the zip archive (without extension).
*
* @param string $filename The current zip archive file name.
* @param array $form The GF form array.
* @param array $entry_ids The entry IDs of all files being added to the archive.
*
* @return string
*/
function my_bdfgf_download_filename( $filename, $form, $entry_ids ) {
// We append the current date/time to the end of the file name.
return $form['title'] . ' - ' . date_i18n( 'Y-m-d H:i:s' );
}
add_filter( 'bdfgf_download_filename', 'my_bdfgf_download_filename', 10, 3 );
/**
* Filter the file name of the zip archive (without extension) just for the form with ID 2.
*
* @param string $filename The current zip archive file name.
* @param array $form The GF form array.
* @param array $entry_ids The entry IDs of all files being added to the archive.
*
* @return string
*/
function my_bdfgf_download_filename_form_id_2( $filename, $form, $entry_ids ) {
// We append the current date/time to the end of the file name.
return $form['id'] . ' - ' . $form['title'] . ' - ' . date_i18n( 'Y-m-d H:i:s' );
}
add_filter( 'bdfgf_download_filename_2', 'my_bdfgf_download_filename_form_id_2', 10, 3 );
@vcat-support
Copy link
Author

The filter can now be used either for all forms or just for a form with a specific ID:

Applies to all forms:

add_filter( 'bdfgf_download_filename', 'my_bdfgf_download_filename', 10, 3 );

Applies to a specific form. In this case, form id 2:

add_filter( 'bdfgf_download_filename_2', 'my_bdfgf_download_filename_form_id_2', 10, 3 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment