Ticket #6762 (new enhancement)

Opened 3 months ago

Last modified 3 months ago

Would be useful for wp_upload_dir to be able to return without date sub directories

Reported by: simonwheatley Assigned to: anonymous
Priority: normal Milestone: 2.6
Component: General Version:
Severity: normal Keywords: has-patch
Cc:

Description

I'm writing a plugin which needs to cache certain web readable files (CSS & JS, etc). The obvious writable directory is wp-content/uploads/, however to work out the filesystem path and web path for this dir is not easy, because wp_upload_dir always returns with the date based subdirs. I could remove the subdirs from the paths afterwards, but this seems needlessly hard.

The attached patch adds an additional argument to wp_upload_dir which requires the function to return the dirs without the date subdirs. The argument defaults to false to maintain backwards compatibility.

Attachments

upload_no_subdirs.patch (0.8 kB) - added by simonwheatley on 04/17/08 15:18:01.
Amend upload_no_subdirs to allow it to return without date sub directories by passing an argument
6762.diff (0.8 kB) - added by DD32 on 04/18/08 01:19:57.

Change History

04/17/08 15:18:01 changed by simonwheatley

  • attachment upload_no_subdirs.patch added.

Amend upload_no_subdirs to allow it to return without date sub directories by passing an argument

(follow-up: ↓ 2 ) 04/18/08 01:19:48 changed by DD32

A Better method would be to simply return 'base_dir' in the $uploads array rather than turning it on/off via a seperate arguement. (See patch)

I needed exactly the same thing in another plugin, but instead i used this in combination with wp_upload_dir():

$uploads_folder = defined('UPLOADS') ? UPLOADS : (trim(get_option('upload_path')) === '' ? 'wp-content/uploads' : get_option('upload_path'));

Another way now that i look at the code again, would be to simply to trim $subdir off the end of the $dir and $url return vals.. But its ugly and could cause problems if the subdir is empty.

04/18/08 01:19:57 changed by DD32

  • attachment 6762.diff added.

(in reply to: ↑ 1 ) 04/18/08 07:53:56 changed by simonwheatley

Replying to DD32:

A Better method would be to simply return 'base_dir' in the $uploads array rather than turning it on/off via a seperate arguement.

That is nicer. Thanks.