Created
April 2, 2014 20:00
-
-
Save noameppel/9941953 to your computer and use it in GitHub Desktop.
Any media file not on development server will be loaded from live server.
This file contains hidden or 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
<?php add_action('init', 'my_replace_image_urls' ); | |
function my_replace_image_urls() { | |
if ( defined('WP_SITEURL') && defined('LIVE_SITEURL') ) { | |
if ( WP_SITEURL != LIVE_SITEURL ){ | |
add_filter('wp_get_attachment_url', 'my_wp_get_attachment_url', 10, 2 ); | |
} | |
} | |
} | |
function my_wp_get_attachment_url( $url, $post_id) { | |
if ( $file = get_post_meta( $post_id, '_wp_attached_file', true) ) { | |
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { | |
if ( file_exists( $uploads['basedir'] .'/'. $file ) ) { | |
return $url; | |
} | |
} | |
} | |
return str_replace( WP_SITEURL, LIVE_SITEURL, $url ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment