NOTE: You do not, under any circumstances, have to do this to continue using WordPress Multisite. I just wanted to see if I could.
I have been toying around with this. Since WP 3.5 doesn’t use ms-files anymore, I wanted to see how much of a pain this would be. While I was at the DMV (I now have a California Drivers License), I started sketching out the methods and possibilities for how one might do this as safely as possible, without bolluxing up your site. I got about 90% successful with it, so this is something I would never suggest you do on a massive, live site. If you compare it to what I did to move images from uploads to blogs.dir for the main site, it’s far more complex and annoying.
Do you have to do this? Again, no! Everything will work just fine. Can you do it? Sure. Why did I? Support. I already know all the mishegas with blogs.dir, but the new location, and it’s lack of ms-files, promises other, weird, errors. I want to repeat, you don’t need to do anything. The Core Team was fantastic with the work they did to turn off ms-files for fresh 3.5 and up installs is nothing short of phenomenal. This was just to assuage my curious nature, and learn more about the way things work.
You ready? Here we go.
I decided to move the images at http://test.ipstenu.org/ to start with, so everything will use that as my example. This is after I played with it on a local site and got my steps mostly solid. I knew that live is always different than test, so I backed up the DB first (always, always, backup first!) and went to town.
Move the images
This is obvious. Move your images from blogs.dir/SITENUM/files/
to /uploads/sites/SITENUM/
(or make an alias). I went and did it via command line in the /uploads/sites/
folder, doing this:
$ cp -r ~/public_html/wp-content/blogs.dir/10/files . $ mv files 10
Lather, rinse, repeat. I could have scripted it, but I was working out the kinks until I had two left.
Edit all sites
Upload Path, Upload URL Path and Fileupload Url. You can blank them all out.(Corrected thanks to Nacin.)
Since you’re blanking it out for everyone you can probably do this via SQL, but since I was doing the sites one at a time, I did them one at a time.
Fix the Database
Search/replace each posts table for each site, changing /files/ to /uploads/SITENUM/
UPDATE wp_10_posts SET post_content = REPLACE ( post_content, '="http://test.ipstenu.org/files/', '="http://test.ipstenu.org/wp-content/uploads/sites/10/');
Why did I do it that way? Because of this blog. I talk a lot about code here, and I know I’ve talked about moving files around before. If you don’t do that, you’re okay with a less precise search, but why bother? This works, it’s safe, and I’d use it again.
That got annoying really fast. I went and grabbed my favorite Search And Replace for WordPress (and any other database) tool. Seriously I love that. I used that to follow up, change everything, and it actually worked really well for me.
Another DB Fix!
One of the changes in 3.5 was turning off rewriting. This took me forever and a day to find. After I did that, my images showed up fine, but the little buggers kept uploading to /files! Turns out it was all because of the site option ms_files_rewriting
The way I got around this was by putting the following in my wp-config.php file:
define( 'UPLOADBLOGSDIR', 'wp-content/uploads/sites' );
And then I ran this in SQL to turn off ms_files_rewriting. Or so I thought. More in a second.
INSERT INTO `my_database`.`wp_sitemeta` (`meta_id`, `site_id`, `meta_key`, `meta_value`) VALUES (NULL, '1', 'ms_files_rewriting', '0');
I came up with that after reading through /wp-includes/functions.php
line 1515.
For most sites, this worked, but in my later work, I determined that it actually wasn’t working. It was ignoring this. I don’t know why, but every test I did merrily ignored this setting, so I finally growled and wrote this mu-plugin function:
function stupid_ms_files_rewriting() { $url = '/wp-content/uploads/sites/' . get_current_blog_id(); define( 'BLOGUPLOADDIR', $url ); } add_action('init','stupid_ms_files_rewriting');
It’s stupid simple, it’s probably not a good idea, but it works for the three sites that have the stupids.
Finish up .htaccess.
.htaccess, remove the ms-files.php line for ms-files, or comment it out. This is pretty simple.
Why not move the main site to /uploads/?
Because of the way I fixed the uploadblogsdir. It defaulted everyone to /sites/ and after an hour I said fuck it.
Any weird problems?
Yeah, two sites (this one and my grandmothers) decided that they wanted to be repetitious and spat out URLs like this: wp-content/uploads/sites/8/sites/8/
Since that wasn’t right at all, and I was a little too eggnoggy to parse why, I did this:
RewriteCond %{HTTP_HOST} ^taffys\.org RewriteRule ^wp-content/uploads/sites/8/sites/8/(.*) /wp-content/uploads/sites/8/$1 [L,R=301]
I swear I have no idea why three sites got stuck with /files/ and two more decided to double down, Vegas style, but frankly I’m pleased I got through this far on my own.
I can’t stress enough that you do not have to do this!