Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#37027 closed defect (bug) (duplicate)

Deletion of post with no title, content & excerpt

Reported by: Ninos Ego Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:


It is not possible to delete (move to trash) posts via admin panel which have no title, content and excerpt.

Steps to reproduce:

  1. 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;
  1. Go to admin panel (/wp-admin/edit.php)
  2. Try to delete this draft (move to trash)
  3. You get a "successfull" message but nothing happend

BTW: With the function wp_delete_post() all's working fine.

Attachments (1)

post.php.patch (590 bytes) - added by Ninos Ego 5 years ago.

Download all attachments as: .zip

Change History (6)

#1 @Ninos Ego
5 years ago

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?

@Ninos Ego
5 years ago

#2 @ocean90
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 @Ninos Ego
5 years ago

  • Component changed from Posts, Post Types to Administration
  • Version set to 4.5.2

User-based solution:

 * 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;

#4 @Ninos Ego
5 years ago

Thank you @ocean90. I'll post my patch in the other ticket

#5 @Ninos Ego
5 years ago

  • Component changed from Administration to Posts, Post Types
  • Version 4.5.2 deleted
Note: See TracTickets for help on using tickets.