I work on a plugin that gets a file uploaded to the upload folder through media. The file is processed if it does not meet x condition the process is aborted and the file is deleted.
The deletion is effective when invoking unlink in this way
if ($counter === 0) {
printMessage('No need to process');
if (unlink($file)) {
printMessage('File removed');
}
return;
}
Here $file
is a reference to wp_handle_upload
$upload['file']
My case is that after verifying that the file has indeed been deleted from the file system, there is a reference to it in the media library.
I appreciate your comments
I work on a plugin that gets a file uploaded to the upload folder through media. The file is processed if it does not meet x condition the process is aborted and the file is deleted.
The deletion is effective when invoking unlink in this way
if ($counter === 0) {
printMessage('No need to process');
if (unlink($file)) {
printMessage('File removed');
}
return;
}
Here $file
is a reference to wp_handle_upload
$upload['file']
My case is that after verifying that the file has indeed been deleted from the file system, there is a reference to it in the media library.
I appreciate your comments
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> ); ?>