Skip to content

Commit f8e48ac

Browse files
authored
gw-zip-files.php: Updated snippet to add support for merge tags in zip files.
1 parent 0433099 commit f8e48ac

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

gravity-forms/gw-zip-files.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function create_zip( $files = array(), $destination = '', $overwrite = fa
307307

308308
public function get_zip_paths( $entry, $type = false ) {
309309

310-
$filename = $this->get_zip_filename( $entry['id'] );
310+
$filename = $this->get_zip_filename( $entry );
311311
$paths = GFFormsModel::get_file_upload_path( $entry['form_id'], $filename );
312312

313313
foreach ( $paths as &$path ) {
@@ -317,8 +317,12 @@ public function get_zip_paths( $entry, $type = false ) {
317317
return $type ? rgar( $paths, $type ) : $paths;
318318
}
319319

320-
public function get_zip_filename( $entry_id ) {
321-
return $this->get_slug( $this->_args['zip_name'], $entry_id, $this->_args['field_ids'] ) . '.zip';
320+
public function get_zip_filename( $entry ) {
321+
$form_id = $entry['form_id'];
322+
$form = GFAPI::get_form( $form_id );
323+
// replace merge tags in the zip file name
324+
$zip_name = GFCommon::replace_variables( $this->_args['zip_name'], $form, $entry, false, false, false, 'text' );
325+
return $this->get_slug( $zip_name, false, $this->_args['field_ids'] ) . '.zip';
322326
}
323327

324328
public function get_meta_key( $entry_id = false ) {
@@ -477,7 +481,7 @@ public function add_zip_as_attachment( $notification, $form, $entry ) {
477481
new GW_Zip_Files(
478482
array(
479483
'form_id' => 123,
480-
'zip_name' => 'my-sweet-archive',
484+
'zip_name' => 'my-sweet-archive', // supports merge tags
481485
'notifications' => array( '5f4668ec2afbb' ),
482486
)
483487
);

0 commit comments

Comments
 (0)