Skip to content

Instantly share code, notes, and snippets.

@axcellence
Last active June 21, 2021 08:59
Show Gist options
  • Save axcellence/221fa2f3759404827f1293326b2e9174 to your computer and use it in GitHub Desktop.
Save axcellence/221fa2f3759404827f1293326b2e9174 to your computer and use it in GitHub Desktop.
Drop these in mu-plugins
<?php
/**
* Plugin name: Remote Media Loader
* Description: Save local storage space by mapping you /uploads directory to your staging or production site
* Author: Axl Crawford
* Author uri: https://www.barques.co.uk/
* License: MIT
*/
// Exclude http://
$local_url = "myproject.local";
// Include http:// or https://
$remote_url = "https://myproject.dev";
if ( $local_url === $_SERVER['HTTP_HOST'] ){
add_filter( 'upload_dir', function ( $uploads ) {
$uploads['baseurl'] = "$remote_url/wp-content/uploads";
return $uploads;
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment