Make WordPress Core

Changeset 13184


Ignore:
Timestamp:
02/17/2010 08:33:29 PM (13 years ago)
Author:
ryan
Message:

Don't require a default category for post types other than 'post'. see #9674

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r13172 r13184  
    20122012    }
    20132013
    2014     // Make sure we set a valid category
     2014    if ( empty($post_type) )
     2015        $post_type = 'post';
     2016
     2017    // Make sure we set a valid category.
    20152018    if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
    2016         $post_category = array(get_option('default_category'));
    2017     }
    2018 
    2019     //Set the default tag list
     2019        // 'post' requires at least one category.
     2020        if ( 'post' == $post_type )
     2021            $post_category = array( get_option('default_category') );
     2022        else
     2023            $post_category = array();
     2024    }
     2025
     2026    // Set the default tag list
    20202027    if ( !isset($tags_input) )
    20212028        $tags_input = array();
     
    20262033    if ( empty($post_status) )
    20272034        $post_status = 'draft';
    2028 
    2029     if ( empty($post_type) )
    2030         $post_type = 'post';
    20312035
    20322036    $post_ID = 0;
     
    24832487function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
    24842488    $post_ID = (int) $post_ID;
     2489    $post_type = get_post_type( $post_ID );
    24852490    // If $post_categories isn't already an array, make it one:
    2486     if (!is_array($post_categories) || 0 == count($post_categories) || empty($post_categories))
    2487         $post_categories = array(get_option('default_category'));
    2488     else if ( 1 == count($post_categories) && '' == $post_categories[0] )
     2491    if ( !is_array($post_categories) || 0 == count($post_categories) || empty($post_categories) ) {
     2492        if ( 'post' == $post_type )
     2493            $post_categories = array( get_option('default_category') );
     2494        else
     2495            $post_categories = array();
     2496    } else if ( 1 == count($post_categories) && '' == $post_categories[0] ) {
    24892497        return true;
    2490 
    2491     $post_categories = array_map('intval', $post_categories);
    2492     $post_categories = array_unique($post_categories);
     2498    }
     2499
     2500    if ( !empty($post_categories) ) {
     2501        $post_categories = array_map('intval', $post_categories);
     2502        $post_categories = array_unique($post_categories);
     2503    }
    24932504
    24942505    return wp_set_object_terms($post_ID, $post_categories, 'category');
Note: See TracChangeset for help on using the changeset viewer.