Make WordPress Core

Changeset 4639


Ignore:
Timestamp:
12/10/2006 08:53:05 PM (17 years ago)
Author:
markjaquith
Message:

wp_delete_category() tweaks and code consolidation. fixes #3463

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-db.php

    r4638 r4639  
    175175
    176176    $cat_ID = (int) $cat_ID;
    177 
    178     // Don't delete the default cat.
    179     if ( $cat_ID == get_option('default_category') )
     177    $default_cat = get_option('default_category');
     178    $default_link_cat = get_option('default_link_category');
     179
     180    // Don't delete either of the default cats
     181    if ( $cat_ID == $default_cat || $cat_ID == $default_link_cat )
    180182        return 0;
    181183
    182     if ( $cat_ID == get_option('default_link_category') )
    183         return 0;
    184 
    185184    $category = get_category($cat_ID);
    186185
    187186    $parent = $category->category_parent;
    188187
    189     // Delete the category.
     188    // Delete the category
    190189    if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
    191190        return 0;
    192191
    193     // Update children to point to new parent.
     192    // Update children to point to new parent
    194193    $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
    195194
    196     // Only set posts and links to the default category if they're not in another category already.
    197     $default_cat = get_option('default_category');
     195    // Only set posts and links to the default category if they're not in another category already
    198196    $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'");
    199     if ( is_array($posts) ) foreach ($posts as $post_id) {
     197    foreach ( (array) $posts as $post_id ) {
    200198        $cats = wp_get_post_categories($post_id);
    201199        if ( 1 == count($cats) )
     
    206204    }
    207205
    208     $default_link_cat = get_option('default_link_category');
    209206    $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'");
    210     if ( is_array($links) ) foreach ($links as $link_id) {
     207    foreach ( (array) $links as $link_id ) {
    211208        $cats = wp_get_link_cats($link_id);
    212209        if ( 1 == count($cats) )
     
    218215
    219216    clean_category_cache($cat_ID);
    220 
    221217    do_action('delete_category', $cat_ID);
    222 
    223218    return 1;
    224219}
Note: See TracChangeset for help on using the changeset viewer.