Skip to content

Commit 692c93e

Browse files
authored
gw-gravity-forms-rename-uploaded-files.php: Fixed an issue where renamed multi-file uploads in Nested Forms became malformed after editing the child entry.
1 parent 6d89429 commit 692c93e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

gravity-forms/gw-gravity-forms-rename-uploaded-files.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* + add a prefix or suffix to file uploads
1414
* + include identifying submitted data in the file name like the user's first and last name
1515
*
16-
* @version 2.6
16+
* @version 2.7
1717
* @author David Smith <[email protected]>
1818
* @license GPL-2.0+
1919
* @link http://gravitywiz.com/rename-uploaded-files-for-gravity-form/
@@ -98,8 +98,25 @@ function rename_uploaded_files( $entry, $form ) {
9898

9999
$result = rename( $file, $renamed_file );
100100

101-
$renamed_files[] = $this->get_url_by_path( $renamed_file, $form['id'] );
101+
if ( ! $result ) {
102+
$renamed_files[] = $_file;
103+
continue;
104+
}
102105

106+
$renamed_url = $this->get_url_by_path( $renamed_file, $form['id'] );
107+
$renamed_files[] = $renamed_url;
108+
109+
// Keep Gravity Forms file-path meta in sync with the renamed URL.
110+
$root = GF_Field_FileUpload::get_upload_root_info( $form['id'] );
111+
gform_update_meta(
112+
$entry['id'],
113+
GF_Field_FileUpload::get_file_upload_path_meta_key_hash( $renamed_url ),
114+
array(
115+
'path' => trailingslashit( $root['path'] ),
116+
'url' => trailingslashit( $root['url'] ),
117+
'file_name' => wp_basename( $renamed_url ),
118+
)
119+
);
103120
}
104121

105122
// In cases where 3rd party add-ons offload the image to a remote location, no images can be renamed.

0 commit comments

Comments
 (0)