Opened 6 years ago
Last modified 15 months ago
#43672 new defect (bug)
wp_delete_post() function ignores `$force_delete` parameter for custom post types
Reported by: | sudar | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | dev-feedback |
Focuses: | administration | Cc: |
Description
The wp_delete_post()
function has a second optional parameter called $force_delete
(default false) that decides whether to send the post to trash or delete it permanently.
But when the function is invoked with a post id that belongs to a custom post type, this parameter is ignored and the post is always deleted permanently and never sent to trash.
Here is the relevant code inside that function that does this.
if ( ! $force_delete && ( 'post' === $post->post_type || 'page' === $post->post_type ) && 'trash' !== get_post_status( $postid ) && EMPTY_TRASH_DAYS ) { return wp_trash_post( $postid ); }
I think the post types check in the above condition should not be made, but I am not sure why it is there and what are the implications of it.
Steps to replicate this issue.
- Create a post in a custom post type and note the post id.
- Make the call to the function. Assuming 42 is the post id, the call will be
wp_delete_post( 42, false)
- Since the
$force_delete
parameter is set tofalse
, the expectation is that the post should be sent to trash - But the post will be permanently deleted
If it is agreed that it is a bug, then I can submit a patch to remove the post type check.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Seems legit. I would approach it using a filter, or maybe an additional
register_post
type argument perhaps: 'trashable'.