#37027 closed defect (bug) (duplicate)
Deletion of post with no title, content & excerpt
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
It is not possible to delete (move to trash) posts via admin panel which have no title, content and excerpt.
Steps to reproduce:
- Create a post with following function
add_filter( 'wp_insert_post_empty_content', 'allow_empty_post' ); $this->post_id = wp_insert_post( array( 'post_type' => 'post' ) ); remove_filter( 'wp_insert_post_empty_content', 'allow_empty_post' ); function allow_empty_post( $boolean ) { return false; }
- Go to admin panel (/wp-admin/edit.php)
- Try to delete this draft (move to trash)
- You get a "successfull" message but nothing happend
BTW: With the function wp_delete_post() all's working fine.
Attachments (1)
Change History (6)
#2
@
5 years ago
- Component changed from Administration to Posts, Post Types
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
- Version 4.5.2 deleted
Duplicate of #30775.
#3
@
5 years ago
- Component changed from Posts, Post Types to Administration
- Version set to 4.5.2
User-based solution:
<?php /** * Allow empty posts in insert function * * @since 1.0.0 * @access public * * @param boolean * @param array * * @return boolean */ add_filter( 'wp_insert_post_empty_content', 'allow_empty_post', 10, 2 ); function allow_empty_post( $maybe_empty, $postarr ) { if ( ! $maybe_empty ) { return $maybe_empty; } if ( 'YOURPOSTTYPE' === $postarr['post_type'] && in_array( $postarr['post_status'], array( 'inherit', 'draft', 'trash', 'auto-draft' ) ) ) { $maybe_empty = false; } return $maybe_empty; }
Note: See
TracTickets for help on using
tickets.
Ok problem found. Post cannot be moved to trash because of the wp_insert_post() which is called in wp_trash_post():
post.php -> wp_trash_post() -> wp_insert_post()
The solution would be to always use the filter 'wp_insert_post_empty_content', what does not make much sense in some scenarios. I think it would be better to implement a patch like attached. What's your opinion about that?