Remote WordPress Media Loader

Let’s assume that you have a public website and would like to make a few changes to the code. So, in keeping with best practices, you setup a local development environment on your computer and copy down the code, database and files for the site. However, this particular site has lots of media and the uploads directory is 10GB in size. If you copy all of that down, it will eat up tons of space on your computer. If you don’t copy it down, you can’t be sure that the site is working properly.

Thankfully, there is a way you can load of those media files from the remote site without having to download them. All you have to do is make sure you have the most recent database from the remote site and drop this code into a file in your mu-plugins/ directory.

Then, just edit the domain in the conditional to match your local development domain and change the uploads base URL to point to the remote site’s uploads URL.

The ideal workflow is that code is always moved from your local development up towards the production site; data and files are always moved from production down towards your local development environment. By using this workflow, you ensure that code changes are consistently deployed and that data conflicts are eliminated. By using this code snippet we no longer have to transfer the actual files, all we need to do is ensure that we have the latest database and we are good to go.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.