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

WordPress Trac noreply at wordpress.org
Tue Feb 3 12:07:49 UTC 2026


#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:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-docs 2nd-opinion     |     Focuses:
  reporter-feedback                              |
-------------------------------------------------+-------------------------
Changes (by ozgursar):

 * keywords:  has-patch needs-testing needs-docs 2nd-opinion => has-patch
     needs-docs 2nd-opinion reporter-feedback


Comment:

 @Fleuv you're correct about the limitation. `UPLOADS` is concatenated with
 ABSPATH (line 2461 according to the latest `trunk`)

 `/wp-includes/functions.php`

 {{{
         /*
          * Honor the value of UPLOADS. This happens as long as ms-files
 rewriting is disabled.
          * We also sometimes obey UPLOADS when rewriting is enabled -- see
 the next block.
          */
         if ( defined( 'UPLOADS' ) && ! ( is_multisite() &&
 get_site_option( 'ms_files_rewriting' ) ) ) {
                 $dir = ABSPATH . UPLOADS;
                 $url = trailingslashit( $siteurl ) . UPLOADS;
         }
 }}}


 However, the `upload_dir` filter may solve this by letting you override
 the calculated paths if used like this:


 {{{
 add_filter('upload_dir', function($uploads) {
     $uploads['basedir'] = '/foo/bar/uploads';
     $uploads['baseurl'] = 'https://example.com/uploads';
     $uploads['path'] = $uploads['basedir'] . $uploads['subdir'];
     $uploads['url'] = $uploads['baseurl'] . $uploads['subdir'];
     return $uploads;
 });
 }}}

 Can you confirm if this doesn't work for your use case?
 Removing `needs-testing` pending clarification.

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


More information about the wp-trac mailing list