I currently use a WordPress network in order to run a number of sites, which all use the same template, plugins and images. As posts appear on a multiple sites, it makes sense to only upload images to one location (and have one copy of an image), rather than multiple ones.
Could I perhaps achieve this by creating a custom rewrite? Or is there a better way to achieve this?
Background information
I am using WPThree Broadcast to ‘broadcast’ an image over multiple sites, and therefore also copy the images into their respective image libraries. I don’t want the server to get cluttered with ten copies of the same image so instead am checking to see if the image is already in a site’s wp_posts
table, and then if not copying the post
and post_meta
data into that site’s tables.
However, I do not wish to copy the actual image into a new upload folder, as the default WP is configured to do (e.g. into /wp-content/blogs.dir/2/files/
), so instead I want all images to be uploaded to /wp-content/uploads/
, the default upload folder for a standard WP installation.
You can pretty simple add some actions to archive this.
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:
In the post “How to Change the Default Media Upload Location in WordPress 3.5” by Editorial Staff, they show how to change the upload dir in
wp-config.php
: