From f4b6050d20c81d08524d1f62c43687dd3213d597 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sun, 10 Dec 2006 20:53:05 +0000 Subject: [PATCH] wp_delete_category() tweaks and code consolidation. fixes #3463 git-svn-id: https://develop.svn.wordpress.org/trunk@4639 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-db.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php index c53d5562c8..7867c6f202 100644 --- a/wp-admin/admin-db.php +++ b/wp-admin/admin-db.php @@ -174,29 +174,27 @@ function wp_delete_category($cat_ID) { global $wpdb; $cat_ID = (int) $cat_ID; + $default_cat = get_option('default_category'); + $default_link_cat = get_option('default_link_category'); - // Don't delete the default cat. - if ( $cat_ID == get_option('default_category') ) - return 0; - - if ( $cat_ID == get_option('default_link_category') ) + // Don't delete either of the default cats + if ( $cat_ID == $default_cat || $cat_ID == $default_link_cat ) return 0; $category = get_category($cat_ID); $parent = $category->category_parent; - // Delete the category. + // Delete the category if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) return 0; - // Update children to point to new parent. + // Update children to point to new parent $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); - // Only set posts and links to the default category if they're not in another category already. - $default_cat = get_option('default_category'); + // Only set posts and links to the default category if they're not in another category already $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'"); - if ( is_array($posts) ) foreach ($posts as $post_id) { + foreach ( (array) $posts as $post_id ) { $cats = wp_get_post_categories($post_id); if ( 1 == count($cats) ) $cats = array($default_cat); @@ -205,9 +203,8 @@ function wp_delete_category($cat_ID) { wp_set_post_categories($post_id, $cats); } - $default_link_cat = get_option('default_link_category'); $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'"); - if ( is_array($links) ) foreach ($links as $link_id) { + foreach ( (array) $links as $link_id ) { $cats = wp_get_link_cats($link_id); if ( 1 == count($cats) ) $cats = array($default_link_cat); @@ -217,9 +214,7 @@ function wp_delete_category($cat_ID) { } clean_category_cache($cat_ID); - do_action('delete_category', $cat_ID); - return 1; }