When you upload a file to Media Library, some data (mainly metadata like title, description, and so on) is stored in database.
So if you delete file using unlink
, you don’t delete any rows from DB – so the attachment will be still visible in Media Library.
If you want to delete attachment from ML, you should use WP functions. wp_delete_attachment
might come in handy.
You can use it like so:
<?php wp_delete_attachment( <ID_OF_YOUR_ATTACHMENT> ); ?>