Ticket #3460 (closed defect: wontfix)

Opened 2 years ago

Last modified 1 year ago

Duplicated default category after deleting a category

Reported by: zhouqb Assigned to: markjaquith
Priority: normal Milestone:
Component: Administration Version: 2.0.5
Severity: normal Keywords: category
Cc: zhouqb@gmail.com

Description

If a category is deleted, all the posts under it will be assigned the default category.

A better approach is checking if it has been assigned another category. If yes, don't apply the default category - that's meaningless.

A real bug is, if the post was assigned both the deleted category and the default, the default will be assigned once more, resulting in two identical rows (except rel_id column) in the wp_post2cat table. Also the fix is adding a check, but following the approach above will avoid such situation.

Attachments

add_to_default_cat_posts_that_only_exist_in_deleted_cat.diff (2.0 kB) - added by markjaquith on 01/30/07 19:11:58.
Patch for 2.0.x

Change History

12/10/06 20:43:07 changed by markjaquith

  • owner changed from anonymous to markjaquith.
  • status changed from new to assigned.
  • milestone changed from 2.1 to 2.0.7.

This has been fixed for 2.1

Possible 2.0.7 milestone.

Here is the 2.1 code, for reference:

	// Only set posts and links to the default category if they're not in another category already.
	$default_cat = get_option('default_category');
	$posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'");
	if ( is_array($posts) ) foreach ($posts as $post_id) {
		$cats = wp_get_post_categories($post_id);
		if ( 1 == count($cats) )
			$cats = array($default_cat);
		else
			$cats = array_diff($cats, array($cat_ID));
		wp_set_post_categories($post_id, $cats);
	}

01/11/07 04:53:15 changed by markjaquith

  • milestone changed from 2.0.7 to 2.0.8.

01/30/07 19:11:39 changed by markjaquith

The functions used to do it in 2.1 (wp_get_post_categories() and wp_set_post_categories() don't exist in 2.0.x

I've attached a patch that should do the equivalent in 2.0.x, but I'd like to save it for another milestone. It's not quite ideal, because it causes one query per post that existed in the category you're deleting.

01/30/07 19:11:58 changed by markjaquith

  • attachment add_to_default_cat_posts_that_only_exist_in_deleted_cat.diff added.

Patch for 2.0.x

03/19/07 18:19:07 changed by foolswisdom

  • milestone changed from 2.0.10 to 2.0.11.

06/04/07 19:01:40 changed by foolswisdom

  • milestone changed from 2.0.11 to 2.0.eventually.

10/03/07 19:37:13 changed by Nazgul

  • status changed from assigned to closed.
  • resolution set to wontfix.
  • milestone deleted.

Closing as wontfix for the 2.0 branch.

MarkJaquith? has stated that only security fixes can go into the 2.0 branch.