File uploads are not deleted using User Registration add-on Update User, when user deletes the file

I have the User Registration add on which I also use for them to update their profile (we link any custom fields to meta fields).

I have added a couple of file uploads fields to save Insurance documents and certificates into their profile for our website admin to view.

These will get replaced every year. So a user can delete for example Insurance.pdf and then upload a new Insurance.pdf.

Problem is, when they delete the file, the file is still stored on the server, even though its not linked to anymore in this field. Uploading a file of the same name adds 1 on the end, or then 2 etc. because it does not overwrite it, it keeps the old file.

How do we delete these old files when the user deletes them from the File upload field please? I dont think its a good idea to store all these old files from so many people for years to come, and then the issue of the filename changing is not good and confuses people.


I also noticed when I deleted the Entries stored for the gravity form, AND then deleted them from Trash, the files deleted. Only when deleting from trash.

So I initially thought maybe tapping into this somehow could delete them, as we dont need to save all these old entries.

BUT when I deleted the older entries, it deleted the files that are supposed to still be there. The update user form still shows a file attached, but that actual file has gone. I think its because the form was saved without changing the file, so the new entry saved an empty file value. The file value was part of an older submission which was deleted and so it deleted the file.

This is not good. We have to keep all entries forever otherwise anyone deleted all these old versions will delete peoples uploaded files.

That’s the expected. Removing a file from the upload field doesn’t affect in any way to the previous entry where the file was uploaded. It only affects to the new submission the user is going to perform. e.g. Like saying “I don’t want to associate this file to my user meta anymore, use this new one instead”.

This is also the expected. Entries and associated files are permanently deleted only after deleting them from the Trash.

That’s correct. As you found already deleting an entry also deletes files uploaded to them. What is saved to the user meta is only the URL to the file, so deleting entries delete the files too, but your user meta still has the URL pointing to it.

Allowing the user to delete previously uploaded files is not a feature of Gravity Forms or the User Registration add-on, that would imply to allow the user to edit entries, and that’s not a feature either. Maybe GravityView could help.

Alternatively, if you want to prevent uploaded files from being deleted when you delete an entry permanently, you can use this filter: gform_field_types_delete_files - Gravity Forms Documentation


add_filter( 'gform_field_types_delete_files', '__return_empty_array' );

Ok Thanks. Very strange its expected behaviour, or at least not have the option to delete files. No user will think this “I don’t want to associate this file to my user meta anymore". People will think its deleted because they clicked a trash icon. So people will assume their document is deleted. Perhaps they need to delete it for GDPR reasons, or just have some other privacy concerns. So they delete it, but its not deleted! I am sure there could be some legal issues there in some circumstances.

In our circumstance, its going to cause filename confusion.

I think we best revert to using an ACF form for updating user data it does not sound like GF is suitable for user update when using files. I am not sure what situation the intended behaviour is good for (when updating user data).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.