Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#6762 closed enhancement (fixed)

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

Reported by: simonwheatley's profile simonwheatley Owned by:
Milestone: 2.6 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: 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 (2)

upload_no_subdirs.patch (846 bytes) - added by simonwheatley 17 years ago.
Amend upload_no_subdirs to allow it to return without date sub directories by passing an argument
6762.diff (787 bytes) - added by DD32 17 years ago.

Download all attachments as: .zip

Change History (5)

@simonwheatley
17 years ago

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

#1 follow-up: @DD32
17 years ago

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.

@DD32
17 years ago

#2 in reply to: ↑ 1 @simonwheatley
17 years ago

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.

#3 @ryan
17 years ago

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

(In [8280]) Return base dir and url from wp_upload_dir(). Props DD32. fixes #6762

Note: See TracTickets for help on using tickets.