Created
July 16, 2013 02:49
-
-
Save tcrsavage/6005369 to your computer and use it in GitHub Desktop.
Replace all broken attachment images with a default image - great for doing local dev with an imported database
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
add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment ) { | |
$content_path = ( defined( 'IMAGE_REPLACER_WP_CONTENT_PATH' ) ) ? IMAGE_REPLACER_WP_CONTENT_PATH : WP_CONTENT_DIR; | |
$content_url = ( defined( 'IMAGE_REPLACER_WP_CONTENT_URL' ) ) ? IMAGE_REPLACER_WP_CONTENT_URL : WP_CONTENT_URL; | |
$file_path = str_replace( $content_url, $content_path, $attr['src'] ); | |
if ( file_exists( $file_path ) ) | |
return $attr; | |
$attr['src'] = ( defined ( 'IMAGE_REPLACER_DEFAULT_IMAGE_URL' ) ) ? IMAGE_REPLACER_DEFAULT_IMAGE_URL : $content_url . '/default.png'; | |
return $attr; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment