1foreach ( $attachments as $attachment ) {
2 if ( false === wp_delete_attachment( $attachment->ID, true ) ) {
3 $file = get_attached_file( $attachment->ID );
4 $file = str_replace( "uploads", "upload-assets", $file);
5 wp_delete_file( $file );
6 }
7 }
8