- WordPress 4.7.2
- Multisite
- Since < 3.5
- As of 2017-02
Introduction
- https://codex.wordpress.org/Multisite_Network_Administration#Uploaded_File_Path
Regardless of WP version, these locations cannot be changed by site admins. Only the network admin can make changes on the site settings page.
But, ‘Upload path’ and ‘Upload Url path’ are ignored and/or changed automatically. Why and What’s happened?
Factors
- Bug #25819
ms_files_rewriting
did not create when the WP updated to 3.5.
ms_files_rewriting
- If this value is “1”, values (on “site settings page”) are ignored.
db_version
and wp-includes/upgrade.php- if
db_version
< “21823”,ms_files_rewriting
is set to “1” in wp-includes/upgrade.php - Even though I had been upgrading,
db_version
is not updated on the WP. It seems that some other conditions or patterns affects this problem.
- if
- wp-includes/ms-default-contstants.php
- If
ms_files_rewriting
is not set in table*_options
or*_sitemeta
it is set to “1” ms_files_rewriting
is used for setting some constants about uploading.
e.g.UPLOADBLOGSDIR
,UPLOADS
,BLOGUPLOADDIR
- If
- wp-includes/functions.php
ms_files_rewriting
is used for setting Upload path and URL path.
upload_path
- Variable to specify where to upload
- Deprecated since 3.5.
Conditions and Patterns
It seems that many conditions and patterns are there.
(Forgive me if I am wrong)
Possible choices
- Pattern #1: Keep on using the “Original”
- What to do:
- Nothing
- Result:
- Directory = ‘wp-content/blogs.dir/(blog_id)/files’
- URL = (site url) +’/(blog name)/files’
- Note:
- ‘Upload path’ and ‘Upload Url path’ are ignored
- Pattern #2: Using values on the site settings page
- What to do:
- Set
ms_files_rewriting
into*_options
asoption_value
= “0” - Set
db_version
to up-to-date. - Result:
- Directory = ‘Upload path’ + ‘sites/(blog_id)’
- URL = ‘Upload Url path’ + ‘sites/(blog_id)’
- Note:
- Values on the site settings page are used but added a suffix
- Pattern #3: Using constant
UPLOADS
- What to do:
- Set
ms_files_rewriting
into*_options
asoption_value
= “0” - Set
db_version
to up-to-date. - Set constant
UPLOADS
- Result:
- Directory =
UPLOADS
+ ‘sites/(blog_id)’ - URL = (site url) +
UPLOADS
+ ‘sites/(blog_id)’ - Note:
- Values on the site settings page are deactivated.
Q. Why is UPLOADBLOGSDIR
not used?
A. Because it is ignored if ms_files_rewriting
is 0.
Problems
Existing problem in Pattern #1
- This pattern remains legacy, complex and much more compatibilities.
It looks dangerous to keep updating the WP.
Expectable problem about Pattern #2
- It is not certain that ‘Upload path’ and ‘Upload Url path’ are remained in future, because these are already removed from Non-Multisite WP.
New Problem comes from Pattern #3
- If (site url) is “/foo/”, (blog_id) is “2” and
UPLOADS
is set as “bar”, URL should be “/foo/bar/sites/2/YYYY/MM/*”, but paths in existing articles should be “/foo/files/YYYY/MM/*”.
Conclusion
- As better is to avoid troubles in future, I choose Pattern #3.
- Old files have to be copied from “/foo/files/*” to “/foo/bar/sites/2/*”.
- For existing articles, RewriteRule should be a solution.
- e.g.
RewriteRule ^/foo/files(.*?)$ /foo/bar/sites/2$1 [R=301,L]
- or replace articles with wp-cli
- e.g.