Skip to content

Commit 19305b2

Browse files
committed
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 e5ae702 commit 19305b2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 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 <david@gravitywiz.com>
1818
* @license GPL-2.0+
1919
* @link http://gravitywiz.com/rename-uploaded-files-for-gravity-form/
@@ -98,11 +98,23 @@ 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'] );
102-
101+
$renamed_url = $this->get_url_by_path( $renamed_file, $form['id'] );
102+
$renamed_files[] = $renamed_url;
103+
104+
// Keep Gravity Forms file-path meta in sync with the renamed URL.
105+
$root = GF_Field_FileUpload::get_upload_root_info( $form['id'] );
106+
gform_update_meta(
107+
$entry['id'],
108+
GF_Field_FileUpload::get_file_upload_path_meta_key_hash( $renamed_url ),
109+
array(
110+
'path' => trailingslashit( $root['path'] ),
111+
'url' => trailingslashit( $root['url'] ),
112+
'file_name' => wp_basename( $renamed_url ),
113+
)
114+
);
103115
}
104116

105-
// In cases where 3rd party add-ons offload the image to a remote location, no images can be renamed.
117+
// In cases where 3rd party add-ons offload the image to a remote location, nfo images can be renamed.
106118
if ( empty( $renamed_files ) ) {
107119
continue;
108120
}

0 commit comments

Comments
 (0)