Opened 5 years ago
Closed 3 years ago
#53084 closed defect (bug) (invalid)
wp_delete_attachment deletes file even if $force_delete is false
| Reported by: | pubalacon | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | reporter-feedback |
| Cc: | Focuses: |
Description (last modified by )
Around line 6085 in wp-includes/post.php
line 6085: wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file );
There is no test of $force_delete, so attachment file is physically removed from system file even if not wanted (or definitely not allowed)
Suggested patch:
if (!$force_delete) {
wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file );
}
Change History (7)
#3
@
5 years ago
- Severity major → normal
Do you have a test case, or were you just reading the code?
The $force_delete variable is checked near the top of the function, and uses an early return, so it matches the description, which says
The attachment is moved to the Trash instead of permanently deleted unless Trash for media is disabled, item is already in the Trash, or $force_delete is true.
if ( ! $force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' !== $post->post_status ) {
return wp_trash_post( $post_id );
}
#5
@
5 years ago
Just noting that code similar to the fragment above can be found not only in wp_delete_attachment(), but also in wp_delete_comment() and wp_delete_post(). Perhaps the $force_delete argument in these functions needs better documentation?
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
3 years ago
#7
@
3 years ago
- Milestone Awaiting Review
- Resolution → invalid
- Status new → closed
Upon review in the Media meeting it was agreed that the docs are pretty clear about the behavior and that this is the intended behavior of the function. If we see more questions around this it would probably be a good move to identify how the docs should be clarified better but for now we should close this to keep the backlog of tickets true.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi and welcome to WordPress Trac! Thanks for the ticket.
wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file );called in wp_delete_attachment function at #L6125.Removing version
5.7.1and set component toMedia