I’ve worked on websites with absolutely massive uploads directories. duPont Registry’s Autofluence blog weighed in at 45GB, and Western Journalism was much larger still (I don’t know exactly how large, I didn’t attempt downloading it all).
Just setting up a development environment could take days, and that’s before I’ve started any actual work on the project. I don’t actually need a copy of all the uploads since I’ll be manually deploying the theme and plugin changes to their staging server. I just didn’t want broken images when my client reviewed the development site.
I came up with a relatively straightforward solution:
- Copy over a few months worth of uploads. This way I can create new image sizes and the first few pages of archives will look right.
- Filter the Image URLs. For any of the images I didn’t move over, use the production site’s URL so that they still load.
I have packaged this up as a plugin: BE Media from Production.
The simplest method is to set the start month and year of the oldest upload directory you carried over. The plugin will automatically create the list of all directories following that. Alternatively, you can manually provide a list of directories to include.
be_media_from_production_url– Specify the Production URL
be_media_from_production_start_month– Specify the Start Month
be_media_from_production_start_year– Specify the Start Year
be_media_from_production_directories– Manually set the upload directories to use
Option 1: In your theme or core functionality plugin, specify the Production URL, Start Month and End Month using the provided filters. Example
Option 2: In your theme or core functionality plugin, specify the Production URL and specific directories using the provided filters. Example
This only affects images generated by WordPress functions like
wp_get_attachment_image(). Any hardcoded image URLs in post content will not be modified. You can use a tool like Search Replace DB 3 to update those URLs.