WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 5 months ago

#27683 new defect (bug)

wp_insert_post_empty_content filter issues with auto-drafts and/or fix auto-draft duplicates

Reported by: hexalys Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5.1
Component: Posts, Post Types Keywords: has-patch dev-feedback
Focuses: Cc:
PR Number:

Description

I have explained the issue at http://wordpress.stackexchange.com/a/140326/31794

The 'wp_insert_post_empty_content' filter can have adverse effects on getting the draft for New Posts (new-post.php)
resulting in numerous PHP Noticesand failure to get the auto-draft record properly.

My suggestion for an intermediate fix would be to replace:

        if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
		if ( $wp_error )
			return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
		else
			return 0;
	}

with:

	if ( $id = apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
		if ( $wp_error )
			return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
		else
			return $id;
	}

That way we can use the filter to prevent duplicates instead of having to resort to extending the db class.

Though ideally a native method to prevent auto-draft duplicates (along the same lines of my code) in wp_insert_post seems best.

I don't know who came up with the cleanup later idea, but it's far from an ideal practice, and as per previous tickets, doesn't always work.

Attachments (1)

27683.diff (688 bytes) - added by MikeHansenMe 5 years ago.
patch based on comment

Download all attachments as: .zip

Change History (4)

@MikeHansenMe
5 years ago

patch based on comment

#1 @MikeHansenMe
5 years ago

  • Keywords has-patch added

#2 @DrewAPicture
4 years ago

  • Keywords dev-feedback added

I'd think we'd probably create issues with developers expecting a return of 0 here. @dd32: Would you mind weighing in here?

#3 @dd32
4 years ago

Changing the return values is going to break someones plugin, returning the values from the filter is going to certainly break someones plugin (Especially as the current use-case would probably be to return true/false).

It seems like the original aim of the ticket, to be able to prevent duplicates, should probably be achieved through filters higher in the stack somewhere

Note: See TracTickets for help on using tickets.