• Hello,

    tl:dr
    When running WordPress from a subfolder I am unable to set a custom uploads directory

    Situation
    Currently I am running 3 websites that all will be having the same codebase.
    They are 3 language versions and die to our current setup and experience, do not want to use a multi site setup.

    In our project we setup WordPress in its own folder in de the root just like the official documentation online detailed.

    The issue comes when we want to create 3 separate folders for all 3 websites but it seems that WordPress can not get this right.

    What I found out
    When looking to create the custom folders I found that just using define('UPLOADS' , 'wp-content/media/com').
    In the media page I can upload an image but it would create the upload directory inside the WordPress subfolder.

    After some debugging and searching through the source code I found that in no situation the “WP_CONTENT_DIR” or “WP_CONTENT_URL” were added to the “UPLOADS” path.
    Every time I found the “UPLOADS” const I would see it being paired with “ABSPATH” and “$siteurl”.

    This means that all things uploaded go to “https://www.example.com/wordpress/wp-content/media/com”.

    But when I leave the “UPLOADS” const empty, or at least don’t define it myself, images are uploaded to the correct location at “https://www.example.com/wp-content/uploads/2022/05”
    Notice that it is not going to the WordPress subfolder.

    Current workaround
    Currently I have create a symlink from the “/wp-content/media/com” to “/wordpress/media/com” folder.
    This seems the work ok but I don’t think this intended to be set up like this.

    I saw on multiple occasions that the “WP_CONTENT_DIR” or “WP_CONTENT_URL” were checked if defined before using it for certain tasks related to media.
    But no such thing happened with the “UPLOADS” const.

    Source
    The reason I come to this possible conclusion is from the file “wp-includes/functions.php” on line 2406.

    Hope somebody can tell me if this is a bug/not implemented feature or I am missing something.

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s intentional that UPLOADS is relative to ABSPATH. As demonstrated in the functions.php line you saw. Thus, if UPLOADS is defined, it must exist in the installation’s directory tree. If you require it to be outside of the installation’s tree, you must relocate all of /wp-content/ with WP_CONTENT_DIR and WP_CONTENT_URL and not define UPLOADS. You are then stuck with using /uploads/ within that location. See line 2385 of the same functions.php. You cannot rename or move /uploads/ further.

    If using symlinks achieves your goals, then it’s reasonable to use that method. It’s not intended you should need to use symlinks, but if it works for you there’s little reason not to.

    Thread Starter controvi

    (@controvi)

    @bcworkz thank you for your reply.
    Like I state, I have moved wordpress to its own subfolder.
    I did the changes to the htaccess and moved the wp-content folder to the root directory.
    And everything is working fine.

    It is just surprising to see that the the WP_CONTENT_DIR is being checked if it is set or not and based on those URL’s something happens.
    I would have thought that the WP_CONTENT_DIR and WP_CONTENT_URL would also be used when setting the UPLOADS folder name.
    Especially as that uses the $site_url var instead of the WP_CONTENT_DIR that I expected it to do.

    As I saw this as not being a bug but just something that was not implemented I didn’t want to make it a bug report but did wonder if I was perhaps missing something.

    It is pretty weird to be able to change the name of the upload folder but than being limited to only using the wordpress core directory.
    That is not something I would have expected. to be honest.

    I did get everything to work by creating a media folder in the /wp-content/ folder and symlinking it to /wordpress/wp-content/media, but it isn’t my preferred route to take.

    Moderator bcworkz

    (@bcworkz)

    I agree, it’s a little weird. I suspect the ability to move wp-content and uploads evolved at different times and not a lot of thought was made to coordinate the two. While clearly intentional, it may not have been fully considered. Wild speculation on my part, I’ve no evidence of this.

    You’re right, it’s not really a bug since it doesn’t break anything, it only limits what’s possible. It is permissible to submit a Trac ticket for suggested enhancements. While Trac is mainly for bug reports, it does have a specific “enhancement” tag you can apply. Submit an enhancement ticket if you like.
    https://core.trac.wordpress.org/newticket

    Be advised that the time before a ticket gets any attention is wildly variable.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress in its own subfolder and custom uploads dir name bug’ is closed to new replies.