Don't set default category when saving an auto-draft. fixes #13531

git-svn-id: https://develop.svn.wordpress.org/trunk@14883 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-05-25 14:43:39 +00:00
parent 83bee6eb2c
commit e63b2b97be
1 changed files with 6 additions and 5 deletions

View File

@ -2174,13 +2174,16 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
if ( empty($post_type) )
$post_type = 'post';
if ( empty($post_status) )
$post_status = 'draft';
if ( !empty($post_category) )
$post_category = array_filter($post_category); // Filter out empty terms
// Make sure we set a valid category.
if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
// 'post' requires at least one category.
if ( 'post' == $post_type )
if ( 'post' == $post_type && 'auto-draft' != $post_status )
$post_category = array( get_option('default_category') );
else
$post_category = array();
@ -2189,9 +2192,6 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
if ( empty($post_author) )
$post_author = $user_ID;
if ( empty($post_status) )
$post_status = 'draft';
$post_ID = 0;
// Get the post ID and GUID
@ -2660,9 +2660,10 @@ function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a
function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
$post_ID = (int) $post_ID;
$post_type = get_post_type( $post_ID );
$post_status = get_post_status( $post_ID );
// If $post_categories isn't already an array, make it one:
if ( !is_array($post_categories) || empty($post_categories) ) {
if ( 'post' == $post_type )
if ( 'post' == $post_type && 'auto-draft' != $post_status )
$post_categories = array( get_option('default_category') );
else
$post_categories = array();