Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#2609 closed defect (bug) (fixed)

Set posts of deleted category on the default category

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

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 16 years ago.
Patch to ensure we don't attempt to delete the default cats

Download all attachments as: .zip

Change History (4)

#1 @westi
16 years ago

  • Milestone set to 2.1
  • Owner changed from anonymous to westi
  • Severity changed from critical to major
  • Status changed from new to 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
16 years ago

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

#2 @westi
16 years ago

  • Keywords bg|has-patch added
  • Severity changed from major to 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
16 years ago

  • Resolution set to fixed
  • Status changed from assigned to 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.