[wp-trac] [WordPress Trac] #27683: wp_insert_post_empty_content filter issues with auto-drafts and/or fix auto-draft duplicates
WordPress Trac
noreply at wordpress.org
Sat Apr 5 07:15:22 UTC 2014
#27683: wp_insert_post_empty_content filter issues with auto-drafts and/or fix
auto-draft duplicates
-------------------------------+-----------------------------
Reporter: hexalys | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 3.5.1
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/27683>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list