Created
March 25, 2015 12:38
-
-
Save mcgregormedia/56eecea0c980ae48cc81 to your computer and use it in GitHub Desktop.
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( 'delete_attachment', 'delete_retina_support_images' ); | |
function delete_retina_support_images( $attachment_id ) { | |
$meta = wp_get_attachment_metadata( $attachment_id ); | |
$upload_dir = wp_upload_dir(); | |
$path = pathinfo( $meta['file'] ); | |
foreach ( $meta as $key => $value ) { | |
if ( 'sizes' === $key ) { | |
foreach ( $value as $sizes => $size ) { | |
$original_filename = $upload_dir['basedir'] . '/' . $path['dirname'] . '/' . $size['file']; | |
$retina_filename = substr_replace( $original_filename, '@2x.', strrpos( $original_filename, '.' ), strlen( '.' ) ); | |
if ( file_exists( $retina_filename ) ) | |
unlink( $retina_filename ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment