Skip to content

Instantly share code, notes, and snippets.

@emaildano
Last active July 26, 2016 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emaildano/2142edb13bf24acca56b0addd5da0129 to your computer and use it in GitHub Desktop.
Save emaildano/2142edb13bf24acca56b0addd5da0129 to your computer and use it in GitHub Desktop.
Serve Remote Assets WP Function
add_filter('upload_dir', 'set_upload_folder', 999);
function set_upload_folder( $upload_data ) {
// absolute dir path, must be writable by wordpress
$upload_data['basedir'] = trailingslashit(ABSPATH). '/wp-content/uploads';
$upload_data['baseurl'] = 'http://example.com/wp-content/uploads';
$subdir = $upload_data['subdir'];
$upload_data['path'] = $upload_data['basedir'] . $subdir;
$upload_data['url'] = $upload_data['baseurl'] . $subdir;
return wp_parse_args($upload_data, $upload_data);
}
// Serve Remote Uploads
function remote_uploads() {
return 'http://example.com/app/uploads';
}
add_filter( 'pre_option_upload_url_path', 'remote_uploads' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment