$deleted = true;
if ( !
empty( $meta['thumb'
] ) ) { // Don't delete the thumb if another attachment uses it.
if ( !
$wpdb->
get_row( $wpdb->
prepare( "SELECT meta_id FROM
$wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' .
$wpdb->
esc_like( $meta['thumb'
] ) . '%',
$post_id ) ) ) { $thumbfile =
str_replace( wp_basename( $file ),
$meta['thumb'
],
$file );
if ( !
empty( $thumbfile ) ) { $thumbfile =
path_join( $uploadpath['basedir'
],
$thumbfile );
$thumbdir =
path_join( $uploadpath['basedir'
],
dirname( $file ) );
if ( !
wp_delete_file_from_directory( $thumbfile,
$thumbdir ) ) { $deleted = false;
} } } } // Remove intermediate and backup images if there are any.
if ( isset( $meta['sizes'
] ) &&
is_array( $meta['sizes'
] ) ) { $intermediate_dir =
path_join( $uploadpath['basedir'
],
dirname( $file ) );
foreach ( $meta['sizes'
] as $size =>
$sizeinfo ) {