Make WordPress Core

Opened 15 years ago

Closed 11 years ago

#19121 closed enhancement (fixed)

Add filter to wp_unique_filename

Reported by: xazure Owned by: swissspidy
Priority: normal Milestone: 4.5
Component: Filesystem API Version: 2.5
Severity: normal Keywords: has-patch commit
Cc: Focuses:

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 15 years ago.
19121.2.patch​ (359 bytes ) - added by SergeyBiryukov 15 years ago.
With $ext
19121.diff​ (619 bytes ) - added by MikeHansenMe 12 years ago.
refreshed with docs
19121.2.diff​ (732 bytes ) - added by swissspidy 11 years ago.
19121.3.diff​ (791 bytes ) - added by johnbillion 11 years ago.
19121.4.diff​ (1.3 KB ) - added by swissspidy 11 years ago.

Download all attachments as: .zip

Change History (22)

#1 @SergeyBiryukov
15 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.

#2 @archon810
14 years ago

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

#3 @archon810
14 years ago

  • Cc admin@… added

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

  • Cc ben@… added

#6 @c3mdigital
13 years ago

  • Component Upload → Filesystem
  • Keywords needs-refresh added
  • Version 3.3 → 2.5

@MikeHansenMe
12 years ago

refreshed with docs

#7 @MikeHansenMe
12 years ago

  • Keywords needs-refresh removed

#9 @jtrobinson
11 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 @swissspidy
11 years ago

  • Milestone Awaiting Review → 4.5
  • Severity major → normal

#11 @swissspidy
11 years ago

  • Keywords commit added

#12 @johnbillion
11 years ago

19121.3.diff​ improves this a bit.

#13 follow-up: @johnbillion
11 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
11 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 @swissspidy
11 years ago

  • Keywords commit added; needs-refresh removed

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

#16 @swissspidy
11 years ago

  • Owner set to swissspidy
  • Resolution → fixed
  • Status new → 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.