WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 4 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)

19121.patch (353 bytes) - added by SergeyBiryukov 8 years ago.
19121.2.patch (359 bytes) - added by SergeyBiryukov 8 years ago.
With $ext
19121.diff (619 bytes) - added by MikeHansenMe 5 years ago.
refreshed with docs
19121.2.diff (732 bytes) - added by swissspidy 4 years ago.
19121.3.diff (791 bytes) - added by johnbillion 4 years ago.
19121.4.diff (1.3 KB) - added by swissspidy 4 years ago.

Download all attachments as: .zip

Change History (22)

#1 @SergeyBiryukov
8 years ago

  • Keywords has-patch added

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.

@SergeyBiryukov
8 years ago

With $ext

#2 @archon810
7 years ago

Any movement here? I'd love to see this in core.

#3 @archon810
7 years ago

  • Cc admin@… added

#4 @markoheijnen
7 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

#5 @husobj
7 years ago

  • Cc ben@… added

#6 @c3mdigital
6 years ago

  • Component changed from Upload to Filesystem
  • Keywords needs-refresh added
  • Version changed from 3.3 to 2.5

@MikeHansenMe
5 years ago

refreshed with docs

#7 @MikeHansenMe
5 years ago

  • Keywords needs-refresh removed

#9 @jtrobinson
4 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.

@swissspidy
4 years ago

#10 @swissspidy
4 years ago

  • Milestone changed from Awaiting Review to 4.5
  • Severity changed from major to normal

#11 @swissspidy
4 years ago

  • Keywords commit added

@johnbillion
4 years ago

#12 @johnbillion
4 years ago

19121.3.diff improves this a bit.

#13 follow-up: @johnbillion
4 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 @swissspidy
4 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.

@swissspidy
4 years ago

#15 @swissspidy
4 years ago

  • Keywords commit added; needs-refresh removed

19121.4.diff is a new patch adding the filter for both return statements.

#16 @swissspidy
4 years ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 36310:

Filesystem API: Add a filter to wp_unique_filename().

Props SergeyBiryukov, MikeHansenMe, johnbillion, swissspidy.
Fixes #19121.

Note: See TracTickets for help on using tickets.