Make WordPress Core

Opened 21 years ago

Closed 21 years ago

#2609 closed defect (bug) (fixed)

Set posts of deleted category on the default category

Reported by: santana Owned by: westi
Priority: normal Milestone: 2.1
Component: Administration Version: 2.0.2
Severity: normal Keywords: Delete category bg|has-patch
Cc: Focuses:

Description

Wordpress allow to set default category in "Options Menù". In "Manage Categories" menù it is written "Deleting a category does not delete posts from that category, it will just set them back to the default category <my_default_category>" but if I delete a category, posts of that category are set on category with ID = 1, Uncategorized Category. This category may not be the default cateroty.


If I can afford, I think that files involved in are:

1- /wordpress/wp-admin/admin-db.php
2- /wordpress/wp-admin/categories.php

I have fixed this problem in this way (lines with "<" are removed, with ">" are added, with "--" are unmodified) :

--- File categories.php --- [around line 47]


< if (1 == $cat_ID)

> if (get_cat_ID(get_catname(get_option('default_category'))) == $cat_ID)
--   die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name));

--- File admin-db.php --- [around line 169 - in wp_delete_category function]



>    $cat_def = get_cat_ID(get_catname(get_option('default_category')));

<    $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'");
>    $wpdb->query("UPDATE $wpdb->post2cat SET category_id='$cat_def' WHERE category_id='$cat_ID'");


MY PLATFORM:

  • O.S.: Debian Testing GNU/Linux - Kernel 2.6.15.4
  • PHP v. 4;
  • MySql v. 4.1;
  • Web Sever: Apache v. 1.3;

Attachments (1)

2609.diff​ (760 bytes ) - added by westi 21 years ago.
Patch to ensure we don't attempt to delete the default cats

Download all attachments as: .zip

Change History (4)

#1 @westi
21 years ago

  • Milestone → 2.1
  • Owner changed from anonymous to westi
  • Severity critical → major
  • Status new → assigned

I think trunk already does some of this looking at the trunk admin-db.php

The first change is definetly needed though.

I'll whip up a patch.

@westi
21 years ago

Patch to ensure we don't attempt to delete the default cats

#2 @westi
21 years ago

  • Keywords bg|has-patch added
  • Severity major → normal

Attached patch should fix this for categories.php

This is belt and braces stuff as we should never be called with the default cats as they don't get an enabled delete link on the UI.

The admin-db.php stuff in wp_delete_category.php looks fine on trunk.

#3 @ryan
21 years ago

  • Resolution → fixed
  • Status assigned → closed

(In [3675]) Add braces in case our belt gives out after a large meal. Props westi. fixes #2609

Note: See TracTickets for help on using tickets.