From 9d7419b50429814887974d6f22d23100c4f3421f Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 23 Jul 2006 18:27:00 +0000 Subject: [PATCH] Default cat deletion fix from westi. fixes #2789 git-svn-id: http://svn.automattic.com/wordpress/branches/2.0@4032 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-db.php | 5 +++-- wp-admin/categories.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php index 89732b8700..d81b6b845a 100644 --- a/wp-admin/admin-db.php +++ b/wp-admin/admin-db.php @@ -156,7 +156,7 @@ function wp_delete_category($cat_ID) { $cat_ID = (int) $cat_ID; // Don't delete the default cat. - if (1 == $cat_ID) + if ($cat_ID == get_option('default_category')) return 0; $category = get_category($cat_ID); @@ -170,7 +170,8 @@ function wp_delete_category($cat_ID) { $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); // TODO: Only set categories to general if they're not in another category already - $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'"); + $default_cat = get_option('default_category'); + $wpdb->query("UPDATE $wpdb->post2cat SET category_id='$default_cat' WHERE category_id='$cat_ID'"); wp_cache_delete($cat_ID, 'category'); wp_cache_delete('all_category_ids', 'category'); diff --git a/wp-admin/categories.php b/wp-admin/categories.php index f70e774d19..30d37c8b4b 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -44,7 +44,8 @@ case 'delete': $cat_name = get_catname($cat_ID); - if ( 1 == $cat_ID ) + // Don't delete the default cats. + if ( $cat_ID == get_option('default_category') ) die(sprintf(__("Can't delete the %s category: this is the default one"), $cat_name)); wp_delete_category($cat_ID);