From 2684a17e83e867eb88c147a412b1cde186473053 Mon Sep 17 00:00:00 2001 From: Russell Heimlich Date: Sat, 9 May 2020 23:52:39 -0400 Subject: [PATCH] --- use-remote-media.php | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 use-remote-media.php diff --git a/use-remote-media.php b/use-remote-media.php new file mode 100644 index 0000000..5bd941f --- /dev/null +++ b/use-remote-media.php @@ -0,0 +1,62 @@ + $val ) { + $absolute_path = str_replace( $base_url, $base_dir, $val['url'] ); + if ( ! file_exists( $absolute_path ) ) { + $val['url'] = str_replace( $find, $replace, $val['url'] ); + $src[ $key ] = $val; + } + } + } + return $src; +} + +function filter_wp_get_attachment_url( $url = '' ) { + if ( is_admin() ) { + return $url; + } + + $wp_upload_dir = wp_upload_dir(); + $base_dir = $wp_upload_dir['basedir']; + $base_url = $wp_upload_dir['baseurl']; + $find = get_site_url(); + $replace = RH_USE_REMOTE_MEDIA_URL; + $absolute_path = str_replace( $base_url, $base_dir, $url ); + if ( ! file_exists( $absolute_path ) ) { + $url = str_replace( $find, $replace, $url ); + } + return $url; +}