Opened 13 years ago
Closed 9 years ago
#19121 closed enhancement (fixed)
Add filter to wp_unique_filename
Reported by: | xazure | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | 2.5 |
Component: | Filesystem API | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Add a filter to wp_unique_filename so it can be modified if necessary.
Currently in wp_handle_upload I am trying to use FTP to put the file elsewhere. Since I can can't use an FTP protocol with move_uploaded_file, I can't just use the upload_dir filter to change the upload directory.
I need to be able to change the unique name directly (so I can look on my FTP server) and then later on I'll handle the move.
There is no way to access this (you can't just affect overrides or anything like that) without completely rebuilding large portions of the uploader. With this one minor hook added, the flexibility becomes much greater.
Attachments (6)
Change History (22)
#4
@
12 years ago
I would love to see this in 3.5. I think it's fine to only add a filter for the callback and not on the return value
#6
@
11 years ago
- Component changed from Upload to Filesystem
- Keywords needs-refresh added
- Version changed from 3.3 to 2.5
#8
@
9 years ago
19121.diff still applies.
#9
@
9 years ago
Any movement on this? We are using a system that offloads the files from the server to cloud storage after a week. Files uploaded after that with the same name as previous ones are colliding. It is more imperative that we be able to do a global check whenever attachments are added (uploaded or sideloaded) that we be able to check if the file exists in cloud storage as well. A filter in wp_unique_filename would allow plugins or themes to do that.
#10
@
9 years ago
- Milestone changed from Awaiting Review to 4.5
- Severity changed from major to normal
#12
@
9 years ago
19121.3.diff improves this a bit.
#13
follow-up:
↓ 14
@
9 years ago
- Keywords commit removed
There is a condition here which returns early from wp_unique_filename()
. Does this value need to pass through the filter too?
#14
in reply to:
↑ 13
@
9 years ago
- Keywords needs-refresh added
Replying to johnbillion:
There is a condition here which returns early from
wp_unique_filename()
. Does this value need to pass through the filter too?
Yeah I think so.
#15
@
9 years ago
- Keywords commit added; needs-refresh removed
19121.4.diff is a new patch adding the filter for both return statements.
wp_unique_filename()
has$unique_filename_callback
, but it doesn't seem to be possible to specify it for core media upload (see #20057 for context), unless I'm missing something.We can probably add a filter there in the same way we did for
wp_unique_post_slug()
in #14111.