Make WordPress Core

Opened 12 years ago

Closed 7 months ago

#27683 closed defect (bug) (wontfix)

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

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

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 11 years ago.
patch based on comment

Download all attachments as: .zip

Change History (5)

@MikeHansenMe
11 years ago

patch based on comment

#1 @MikeHansenMe
11 years ago

  • Keywords has-patch added

#2 @DrewAPicture
10 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
10 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

#4 @callumbw95
7 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

Hi all,

After reviewing the full history of the discussion, it's clear that the initially proposed solution of changing the return value for the wp_insert_post_empty_content filter introduces a significant backward-compatibility issue. As noted by @dd32, many existing plugins will be expecting a boolean return, and altering this to return a post ID would cause unexpected behavior and break sites.

While the underlying issue of managing auto-draft creation is valid, the consensus is that modifying this filter is not the correct approach. A solution for preventing duplicate auto-drafts would need to be implemented higher in the stack to avoid these conflicts.

Given the significant backward-compatibility concerns and the lack of a viable alternative proposal within this ticket for many years, I am closing this ticket as wontfix. However, please feel free to reopen this ticket if you wish to discuss this further or propose a new, backward-compatible patch.

Note: See TracTickets for help on using tickets.