Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#17425 closed enhancement (invalid)

Add filter for $uploads in wp_handle_upload

Reported by: iandunn Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Media Keywords: needs-patch reporter-feedback close
Focuses: Cc:


Right now there isn't any way for a plugin to set a custom directory for file uploads. I understand that in most cases they should be placed in the default directory, but there are circumstances where this isn't desirable. For instance, I'm building a custom post type for a client, and they have a separate application that it will integrate with. That application has to have the files in a specific directory structure which can't be changed.

The only thing needed to get around this is a filter on $uploads.

$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); // unmodified, just here to show placement
$uploads = apply_filters( 'wp_handle_upload_uploads', $uploads );

Change History (3)

comment:1 @duck_4 years ago

  • Keywords reporter-feedback close added

Use the upload_dir filter in wp_upload_dir()?

comment:2 @iandunn4 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Ah, crap, you're right, I missed that. Sorry for the unnecessary report.

I guess my problem now is that I need to find a way to only change the directory only for files my plugin uploads, rather than globally. Maybe I can hook into that before the upload and change it if post_type == 'my_custom_type', and then set it back after the upload.

comment:3 @duck_4 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.