Hi,
Thank you for your interesting question. It can indeed be cumbersome to delete your download files afterwards via the media library. To automatically remove the corresponding download file from the media library when you normally remove a download, you can use the following PHP code:
add_action( 'before_delete_post', 'delete_dae_attachment', 10, 2 );
function delete_dae_attachment( $post_id, $post ) {
if ( 'dae_download' != $post->post_type ) {
return;
}
// If a post with post_type dae_download is permanently deleted, permanently delete attachment as well
$dae_settings = get_post_meta( $post_id, 'dae_settings', true );
if ( ! empty( $dae_settings['file_id'] ) ) {
$attachment_id = (int) $dae_settings['file_id'];
wp_delete_attachment( $attachment_id, true );
}
}
Although this is a tested and working code, it is always advisable to test the code first before using it on a live site.
We will think about an option to integrate this functionality in the future.
Kind regards,
Team Download After Email