admin管理员组文章数量:1130349
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
Share Improve this question asked Dec 10, 2018 at 23:17 user615274user615274 1237 bronze badges1 Answer
Reset to default 3When 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> ); ?>
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
Share Improve this question asked Dec 10, 2018 at 23:17 user615274user615274 1237 bronze badges1 Answer
Reset to default 3When 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> ); ?>
本文标签:
版权声明:本文标题:plugin development - Why after a file is programmatically deleted, is there still a reference in the media library? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749110254a2317265.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论