Skip to content

Commit

Permalink
gw-zip-files.php: Updated snippet to add support for merge tags in …
Browse files Browse the repository at this point in the history
…zip files.

`gw-zip-files.php`: Updated snippet to add support for merge tags in zip files.

`gw-zip-files.php`: Updated snippet to add support for merge tags in zip files.
  • Loading branch information
saifsultanc committed Jan 15, 2025
1 parent 68f6691 commit ec24bc7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions gravity-forms/gw-zip-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function create_zip( $files = array(), $destination = '', $overwrite = fa

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

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

foreach ( $paths as &$path ) {
Expand All @@ -315,8 +315,12 @@ public function get_zip_paths( $entry, $type = false ) {
return $type ? rgar( $paths, $type ) : $paths;
}

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

public function get_meta_key( $entry_id = false ) {
Expand Down Expand Up @@ -475,7 +479,7 @@ public function add_zip_as_attachment( $notification, $form, $entry ) {
new GW_Zip_Files(
array(
'form_id' => 123,
'zip_name' => 'my-sweet-archive',
'zip_name' => 'my-sweet-archive', // supports merge tags
'notifications' => array( '5f4668ec2afbb' ),
)
);

0 comments on commit ec24bc7

Please sign in to comment.