Using same directory for storing all uploaded images on a WordPress network

You can pretty simple add some actions to archive this.

function wpse_16722_main_uploads() {
    switch_to_blog(1);
}
add_action('load-media-new.php', 'wpse_16722_main_uploads');
add_action('load-media-upload.php', 'wpse_16722_main_uploads');
add_action('load-media.php', 'wpse_16722_main_uploads');
add_action('load-upload.php', 'wpse_16722_main_uploads');
add_action('admin_init', 'wpse_16722_main_uploads');

This will change the current sub-blog to user your main-site with the help of switch_to_blog and of course you want the main side by the id 1.

You can also add a function to rewrite the upload folder to only /uploads without the subdirs:

function wpse_16722_upload_dir( $args ) {
    $newdir="https://wordpress.stackexchange.com/";

    $args['path']    = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
    $args['url']     = str_replace( $args['subdir'], '', $args['url'] );      
    $args['subdir']  = $newdir;
    $args['path']   .= $newdir; 
    $args['url']    .= $newdir; 

    return $args;
}
add_filter( 'upload_dir', 'wpse_16722_upload_dir' );

Leave a Comment