Make WordPress Core


Ignore:
Timestamp:
05/23/2007 10:03:24 PM (19 years ago)
Author:
ryan
Message:

wp_delete_term(). see #4189

File:
1 edited

Legend:

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

    r5528 r5533  
    151151
    152152        $cat_ID = (int) $cat_ID;
    153         $default_cat = get_option('default_category');
    154         $default_link_cat = get_option('default_link_category');
    155 
    156         // Don't delete either of the default cats
    157         if ( $cat_ID == $default_cat || $cat_ID == $default_link_cat )
    158                 return 0;
    159 
    160         $category = get_category($cat_ID);
    161 
    162         $parent = $category->category_parent;
    163 
    164         // Delete the category if it is not also a tag.
    165         if ( 0 == ($category->type & TAXONOMY_TAG) ) {
    166                 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
    167                         return 0;
    168         } else {
    169                 $wpdb->query("UPDATE $wpdb->categories SET type = type & ~" . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_ID'");
    170         }
    171         // Update children to point to new parent
    172         $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
    173 
    174         // Only set posts and links to the default category if they're not in another category already
    175         $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID' AND rel_type = 'category'");
    176         foreach ( (array) $posts as $post_id ) {
    177                 $cats = wp_get_post_categories($post_id);
    178                 if ( 1 == count($cats) )
    179                         $cats = array($default_cat);
    180                 else
    181                         $cats = array_diff($cats, array($cat_ID));
    182                 wp_set_post_categories($post_id, $cats);
    183         }
    184 
    185         $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'");
    186         foreach ( (array) $links as $link_id ) {
    187                 $cats = wp_get_link_cats($link_id);
    188                 if ( 1 == count($cats) )
    189                         $cats = array($default_link_cat);
    190                 else
    191                         $cats = array_diff($cats, array($cat_ID));
    192                 wp_set_link_cats($link_id, $cats);
    193         }
    194 
    195         clean_category_cache($cat_ID);
    196         do_action('delete_category', $cat_ID);
    197         return 1;
     153        $default = get_option('default_category');
     154
     155        // Don't delete the default cat
     156        if ( $cat_ID == $default )
     157                return 0;
     158
     159        return wp_delete_term($cat_ID, 'category', "default=$default");
    198160}
    199161
Note: See TracChangeset for help on using the changeset viewer.