I am trying to sharding BLOGUPLOADDIR but couldnt success atm. This is default one:
define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
I am trying to set it:
if($wpdb->blogid<10){
$bloggroup = 'global';
}else{
$bloggroup = 'bloggroup'.floor($wpdb->blogid/2000+1); // 1999->1, 2000->2
}
define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$bloggroup}/{$wpdb->blogid}/files/" );
So every 2000 blog, bloggroup will change.. I tried upload_dir
filter but i need to define before it. I tried sunrise.php but $wpdb->blogid is not defined in there it seems. Whats propery way of this?
Copy the body of
wp-includes/ms-settings.php
intosunrise.php
, from line 25 to line 127. At the bottom, add yourBLOGUPLOADDIR
defines.ms-settings.php
will loadsunrise.php
. When execution returns toms-settings.php
, it will see that$current_site
and$current_blog
are set, and it will skip that huge if statement. Just remember to update your sunrise.php when you upgrade WordPress.Extreme hacky solution that doesn’t require copypasta would involve one of the
wp_start_object_cache()
overrides (the only hookable functionality between discovering$current_blog
and callingms_upload_constants()
), but let’s not go there.Define it in wp-config.php. The problem is you won’t have access to the $wpdb->blogid but try to create a special internal encoding for each blog (by subdomain or domain/first-slice-of-path). In worst case, you can do a quick mysql connection and grab the blog ID yourself. Once you find it in the DB, store it in an XML or something.
Plugins kick in way after the constant is defined so, unless you’re willing to do a tiny hack to the core :)… your only chance is the use of wp-config.php plus some **custom blog_id**s you’d have to manually (by code) generate and manage.
It’s doable, it just requires a bit of extra work, custom tailored for your environment…