[wp-trac] [WordPress Trac] #43672: wp_delete_post() function ignores `$force_delete` parameter for custom post types
WordPress Trac
noreply at wordpress.org
Mon Apr 2 05:23:03 UTC 2018
#43672: wp_delete_post() function ignores `$force_delete` parameter for custom post
types
-------------------------------+-----------------------------
Reporter: sudar | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: trunk
Severity: normal | Keywords:
Focuses: administration |
-------------------------------+-----------------------------
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 to `false`, 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43672>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list