Skip to content

Commit ba19c90

Browse files
committed
gw-zip-files.php: Updated snippet to ensure all nested form entry uploads are added to zip.
1 parent abfb441 commit ba19c90

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

gravity-forms/gw-zip-files.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,23 @@ public function archive_files( $entry, $form ) {
8080
continue;
8181
}
8282
$nested_form = GFAPI::get_form( $nested_entry['form_id'] );
83-
$nested_archive_files = array_merge( $nested_archive_files, $this->get_entry_files( $nested_entry, $nested_form ) );
83+
// Add each nested entry files list as a separate array to avoid overriding previously saved files with the same associative array key (the field id).
84+
$nested_archive_files = array_merge( $nested_archive_files, array( $this->get_entry_files( $nested_entry, $nested_form ) ) );
8485
}
8586
}
8687

87-
$archive_files = $this->get_entry_files( $entry, $form );
88+
// For conformity with the $nested_archive_files, the current (parent) entry files are also loaded onto an array.
89+
$archive_files = array( $this->get_entry_files( $entry, $form ) );
8890
$archive_files = array_merge( $archive_files, $nested_archive_files );
8991
if ( empty( $archive_files ) ) {
9092
return;
9193
}
9294

93-
$archive_file_paths = wp_list_pluck( $archive_files, 'path' );
95+
$archive_file_paths = array();
96+
foreach ( $archive_files as $archive_file ) {
97+
$archive_file_path = array_values( wp_list_pluck( $archive_file, 'path' ) );
98+
$archive_file_paths = array_merge( $archive_file_paths, $archive_file_path );
99+
}
94100

95101
$zip = $this->create_zip( $archive_file_paths, $this->get_zip_paths( $entry, 'path' ) );
96102
if ( $zip ) {

0 commit comments

Comments
 (0)