Media Uploader: get deleted files

Without seeing your “list editor” code I can only provide a theoretical answer.

when a file is deleted in the media uploader, I also want it removed from the list the user is currently editing, so the files can’t be saved to my custom database table when it no longers exists in the “media environment”. I know which javascript I need for removing them from my list, but I don’t know how to get the deleted files from the media uploader.

Before you save the list to your custom database table do a quick check if these media files exist in WordPress Media Library and filesystem.

Exact solution depends on how you are saving to your custom database table. If you are using the WordPress Core APIs then this might help you: http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data.

For example:

<?php
function so111965_filter_deleted_handler( $data , $postarr ) {
  // do the filtering of deleted files here
  return $data;
}

add_filter( 'wp_insert_post_data', 'so111965_filter_deleted_handler', '99', 2 );
?> 

Leave a Comment