If you’re writing a lot of code, you’re most probably doing so on a local (development) version of a live (production) site. This is a great way to work but if there is a large media library, it can be a bit of a pain syncing all those files down to your local machine.
A good workaround is to rewrite requests made to the uploads directory so that the requests are actually forwarded to the live site. This generally requires some knowledge about managing server configuration through .htaccess or through the NGINX config which isn’t necessarily everyone’s cup of tea.
I recently had to knock up a quick solution that we could use in a staging environment to save on disk use. My quick solution was to hook into WordPress’ media functions and just replace the host name for image URLs as they are generated.
A simple plugin solution for loading images remotely in staging/development
I’ve put together a simple plugin that you can use to do the same. You’ll need to configure a couple of constants in your wp-config.php
file as demonstrated further down.
Configuring the plugin
To configure, simply add a couple of constants in your wp-config.php
file:
Not for production!
It should be pretty clear that this isn’t a plugin that should be active on your production site. As part of our automated deployment process, this plugin gets activated in the staging environment and deactivated and removed in the production environment.