[wp-trac] [WordPress Trac] #45725: Unable to use the UPLOADS constant with WordPress in a different directory

WordPress Trac noreply at wordpress.org
Thu Dec 20 13:07:46 UTC 2018


#45725: Unable to use the UPLOADS constant with WordPress in a different directory
-------------------------+-------------------------------------------------
 Reporter:  Fleuv        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Upload       |    Version:  trunk
 Severity:  normal       |   Keywords:  has-patch needs-testing needs-docs
  Focuses:               |  2nd-opinion
-------------------------+-------------------------------------------------
 === The problem ===
 When WordPress is installed in a different directory (you can achieve that
 by following
 [[https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory|these
 instructions]]), the **UPLOADS** constant is unable to function correctly
 in some cases according to the **wp_upload_dir()**'s output. Occasionally
 the constant accepts a relative path what will be appended to the
 **ABSPATH** constant to determine the **basedir** and to the
 **site_url()** function to determine the **baseurl** for the uploads
 location.

 Although WordPress does let you move the CMS (it actually can be anywhere
 on the filesystem), however the uploads directory will always be relative
 to the CMS directory (**ABSPATH** constant) when using the **UPLOADS**
 constant.

 === The use case ===
 There are multiple use cases which will be affected by this but let's
 consider the next few parameters:

 * Website URL: example.com
 * Website DIR: /foo/bar
 * WordPress URL: example.com/wordpress
 * WordPress DIR: /foo/bar/wordpress

 Our goal is to store uploads at:

 * Uploads URL: example.com/uploads
 * Uploads DIR: /foo/bar/uploads

 However when we defining the UPLOADS constant as 'uploads', will result in
 the following:

 * Uploads URL: example.com/wordpress/uploads
 * Uploads DIR: /foo/bar/wordpress/uploads

 You might wonder what will happen when we use an absolute value for the
 constant instead, in this case '/foo/bar/uploads' is used:

 * Uploads URL: example.com/wordpress//foo/bar/uploads
 * Uploads DIR: /foo/bar/wordpress//foo/bar/uploads

 === The solution ===
 Possible solutions where I could came up with are, the two following:

 * Add another constant like **ABSPATH** to the index.php, this could be
 tricky for some people to update but the benefits of it are very useful.
 It will allow you to use one WordPress installation for all your WordPress
 websites. How you might wonder?
 [[https://stackoverflow.com/a/39195424/3157038|This is how]], I've been
 using this already for years!
 * Another solution could be to introduce a new constant specifically for
 the uploads directory path and only use the current **UPLOADS** constant
 for the url.

 Both of these solutions require to be implemented into the
 **_wp_upload_dir()** function
 [[https://core.trac.wordpress.org/browser/tags/5.0/src/wp-
 includes/functions.php#L1972|on line 1972 in wp-includes/functions.php]]

 Have a look at the patch attached to this ticket, with the patch WordPress
 will introduce both the **UPLOADS_DIR** and **INDEX_ABSPATH** constant.
 According to some tests I did it should also be backward compatible.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45725>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list