Unfortunately, WordPress auto-draft can’t be disabled, especially if you’re using post editor through your dashboard to write a post. Auto-draft will not be created if you’re call wp_insert_post() directly from your script or plugin. Unlike autosave or post revision that can be easily bypassed by line of code, auto-draft just leave as is. I don’t know how important it is and what exaclty happened in the backend so WordPress keep auto-draft to be created.
Despite that WordPress cleaning up auto-draft every 24 hours, still, it makes some peoples feel inconvenience, because it leaves unused ID in the database.
My solution
1. Disable auto-draft deleting schedule. It’s important because we need it’s ID to be reserved.
2. Redirect “New Post” to “Edit Post” if auto-draft exists in the database. This will use auto-draft ID as the ID of your new post.
The fun part
/**
* fix autodraft,sometimes WordPress can be sucks too..
* @author: takien
*/
remove_action( 'wp_scheduled_auto_draft_delete', 'wp_delete_auto_drafts',10 );
add_action('admin_init','takien_fix_autodraft');
function takien_fix_autodraft() {
global $pagenow,$typenow;
if( 'post-new.php' == $pagenow ) {
$args = Array(
'post_type' => $typenow,
'posts_per_page'=> 1,
'order' => 'ASC',
'post_status' => 'auto-draft',
'author' => get_current_user_id()
);
$expected_draft = get_posts($args);
if(isset($expected_draft[0])) {
$id = $expected_draft[0]->ID;
if ( current_user_can( 'edit_post', $id ) AND (!wp_check_post_lock( $id )) ) {
$link = get_edit_post_link( $id, false );
if( $link ) {
wp_redirect($link);
exit;
}
}
}
}
}
Copy and paste or re-type (seriously) the above code to your functions.php of your theme or your plugin file.
Now, whenever you hit “Post New” to create post, it will be redirected to edit post, eg wp-admin/post.php?post=10&action;=edit if there is unused auto-draft in database. Where 10 is the ID of the auto-draft.
To prevent conflict, the code above also check for post type and author, to ensure that auto-draft also has same post_type and author as the post you want to create.