diff --git a/gravity-forms/gw-gravity-forms-rename-uploaded-files.php b/gravity-forms/gw-gravity-forms-rename-uploaded-files.php index bc37b0615..d1bb633b3 100644 --- a/gravity-forms/gw-gravity-forms-rename-uploaded-files.php +++ b/gravity-forms/gw-gravity-forms-rename-uploaded-files.php @@ -13,7 +13,7 @@ * + add a prefix or suffix to file uploads * + include identifying submitted data in the file name like the user's first and last name * - * @version 2.6 + * @version 2.7 * @author David Smith * @license GPL-2.0+ * @link http://gravitywiz.com/rename-uploaded-files-for-gravity-form/ @@ -98,8 +98,25 @@ function rename_uploaded_files( $entry, $form ) { $result = rename( $file, $renamed_file ); - $renamed_files[] = $this->get_url_by_path( $renamed_file, $form['id'] ); + if ( ! $result ) { + $renamed_files[] = $_file; + continue; + } + $renamed_url = $this->get_url_by_path( $renamed_file, $form['id'] ); + $renamed_files[] = $renamed_url; + + // Keep Gravity Forms file-path meta in sync with the renamed URL. + $root = GF_Field_FileUpload::get_upload_root_info( $form['id'] ); + gform_update_meta( + $entry['id'], + GF_Field_FileUpload::get_file_upload_path_meta_key_hash( $renamed_url ), + array( + 'path' => trailingslashit( $root['path'] ), + 'url' => trailingslashit( $root['url'] ), + 'file_name' => wp_basename( $renamed_url ), + ) + ); } // In cases where 3rd party add-ons offload the image to a remote location, no images can be renamed.