Remote Media Library
A WordPress must-use plugin that replaces local media URLs with production URLs, allowing developers to work in local environments without downloading all media files.
by Andrew Miller @ 84EM · github.com/84emllc/remote-media-library · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/84emllc/remote-media-library/archive/refs/heads/main.zipA WordPress must-use plugin that replaces local media URLs with production URLs, allowing developers to work in local environments without downloading all media files.
Description
Remote Media Library automatically rewrites URLs pointing to wp-content/uploads on local development environments to point to your production site instead. This eliminates the need to sync gigabytes of media files to your local machine while developing.
Features
- Automatically detects local development environments
- Replaces media URLs in real-time before page output
- Zero configuration after initial setup
- No database tables or stored options
- Skips admin pages to keep WordPress media library functional
- Lightweight with minimal performance impact
- Must-use plugin - always active, cannot be accidentally deactivated
Requirements
- WordPress 4.0 or higher
- PHP 7.4 or higher
Installation
As a must-use plugin, installation is simple:
-
Copy
0000-remote-media-library.phpto your WordPressmu-pluginsdirectory:cp 0000-remote-media-library.php wp-content/mu-plugins/Or if using a subdirectory structure:
mkdir -p wp-content/mu-plugins/remote-media-library cp 0000-remote-media-library.php wp-content/mu-plugins/remote-media-library/ -
Configure the production URL (see Configuration section below)
Note: Must-use plugins are automatically activated and cannot be deactivated through the WordPress admin interface. They also don't appear in the regular plugins list.
Configuration
Edit 0000-remote-media-library.php and update the following constants:
const LIVE_URL = 'https://example.com'; // Your production site URL
const LOCAL_URLS = [ '.local', '.test', '.dev', '.box' ]; // Local domain patterns
const PATH_TO_CHECK = '/wp-content/uploads/'; // Upload directory path
Configuration Options
- LIVE_URL: The full URL of your production site (no trailing slash)
- LOCAL_URLS: Array of strings to detect local environments. The plugin activates if the home URL contains any of these strings.
- PATH_TO_CHECK: The path to your uploads directory (default:
/wp-content/uploads/)
How It Works
- The plugin checks if the site is running in a local environment by matching the home URL against
LOCAL_URLSpatterns - On the
template_redirecthook, if the site is local and not in admin, output buffering begins - During output buffering, a callback function processes the HTML content
- All instances of your local uploads URL are replaced with the production uploads URL
- The callback also handles escaped versions of URLs (for JSON, etc.)
- The modified HTML is sent to the browser
Use Cases
This plugin is ideal for:
- Development teams working with sites that have large media libraries
- Agencies managing multiple client sites with extensive image galleries
- Developers with limited local storage or bandwidth
- Teams wanting faster local environment setup
Limitations
- Only works on the frontend (admin is intentionally excluded)
- Requires production site to be publicly accessible
- May have minor performance impact on pages with large HTML output
- Does not handle media uploads from local environments
License
GPL-2.0+
Author
Andrew Miller @ 84EM https://84em.com
Development
Pull requests welcome.