Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#37743 closed defect (bug) (wontfix)

Setting UPLOADS constant's path prefixes the path with ABSPATH instead of WP_CONTENT_DIR

Reported by: jtwebb's profile jtwebb Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description

On line 1921 if wp-includes/functions.php the base path of the $dir variable is WP_CONTENT_DIR. But if you set the UPLOADS constant, then the prefixing path is ABSPATH (line 1941).

This works fine if your uploads directory is in the ABSPATH directory. But if you have the WordPress source in a different directory than your content, you can't set the path appropriately.

Use case:
WordPress source lives in a 'src' directory.
WordPress content (plugins, themes, uploads) live in 'app' directory, a sibling of 'src'
You want to rename the uploads directory to 'media' or something more semantic to what you're using it for.

The way wp-includes/functions.php is setup now, getting the above scenario is impossible unless someone hacks the core.

Suggested fix: Don't prefix the UPLOADS constant with anything. Allow the user to set the root path.

That would mean changing line 1941 from
$dir = ABSPATH . UPLOADS;
to
$dir = UPLOADS;

Change History (4)

#1 follow-up: @dd32
9 years ago

  • Component changed from General to Media
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Hi @jtwebb,

We can't change the behaviour of the UPLOADS constant, as it's documented to be relative to ABSPATH.

The options you have available to you are:

  • Set UPLOADS for relative to ABSPATH
  • Set WP_CONTENT_DIR and have the uploads live at WP_CONTENT_DIR/uploads
  • Use the upload_path and upload_dir options within WordPress, which may be absolute OR relative to ABSPATH. (See Settings -> Media)
  • Use the upload_dir filter and set it to something completely custom

With those options available to you, I don't think we're going to add a new constant for an absolute path to the uploads directory.
WordPress encourages the usage of filters over constants, as they're much more flexible, and the options allow changing it for most other use-cases.
While I'm marking this ticket as wontfix it's possible to continue discussion, and a Trac gardener can re-open it if needed.

#2 @swissspidy
9 years ago

  • Version 4.6 deleted

#3 in reply to: ↑ 1 @jtwebb
9 years ago

Thanks for the response. Prefixing the path two different ways in the same function seemed like a bug. But since that is by design I'll try something else.

The first two options won't work for my scenario.

The third option wouldn't work in my situation either, because the function checks to see if it's an absolute path by checking if it has the ABSPATH in it. If it doesn't (which it wouldn't if WP_CONTENT_DIR and ABSPATH are siblings) then it prefixes the path with ABSPATH.

I'll give the fourth one a try. I wasn't familiar with that filter. But if I can set that to be completely custom, it should work for me.

Again, I really appreciate your response!

#4 @issactrotts
7 years ago

#43047 was marked as a duplicate.

Note: See TracTickets for help on using tickets.