diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index a0a4d8d99..1769b597c 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -117,7 +117,7 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) { $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); $pad = str_repeat('— ', $level); if ( $user_level > 3 ) - $edit = "" . __('Edit') . "cat_name)) . "')\" class='delete'>" . __('Delete') . ""; + $edit = "" . __('Edit') . "cat_name)) . "')\" class='delete'>" . __('Delete') . ""; else $edit = ''; diff --git a/wp-admin/categories.php b/wp-admin/categories.php index ac574389a..46e29234b 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -38,26 +38,27 @@ case 'addcat': header('Location: categories.php?message=1#addcat'); break; -case 'Delete': +case 'delete': - check_admin_referer(); + check_admin_referer(); - $cat_ID = intval($_GET["cat_ID"]); - $cat_name = get_catname($cat_ID); - $category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); - $cat_parent = $category->category_parent; + $cat_ID = (int) $_GET['cat_ID']; + $cat_name = get_catname($cat_ID); + $category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); + $cat_parent = $category->category_parent; - if (1 == $cat_ID) - die(sprintf(__("Can't delete the %s category: this is the default one"), $cat_name)); + if ( 1 == $cat_ID ) + die(sprintf(__("Can't delete the %s category: this is the default one"), $cat_name)); - if ($user_level < 3) - die (__('Cheatin’ uh?')); + if ( $user_level < 3 ) + die (__('Cheatin’ uh?')); - $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); - $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$cat_parent' WHERE category_parent = '$cat_ID'"); - $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'"); + $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); + $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$cat_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'"); - header('Location: categories.php?message=2'); + header('Location: categories.php?message=2'); break;