Last active
December 29, 2015 08:19
-
-
Save beneverard/7642928 to your computer and use it in GitHub Desktop.
Rewrite attachment URLs from a local version of WordPress to a remote version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remove username:password if you don't need htpasswd auth | |
add_filter('wp_get_attachment_url', function($url) { | |
$upload_dir = wp_upload_dir(); | |
$file_path = str_replace(site_url() . '/wp-content/uploads', $upload_dir['basedir'], $url); | |
// check to see if the file exists locally first | |
if ( file_exists($file_path) ) { | |
return $url; | |
} | |
return str_replace(site_url(), 'http://username:[email protected]', $url); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Possible improvements, check if file exists locally... if not, try and load remote version.