#9335 closed defect (bug) (fixed)
Child categories error out as duplicates even if slugs and parent categories are different
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | 2.7.1 |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
In short, child (sub) categories seem to be not allowed and error out as duplicates if another exists with that name, even though the slug and parent categories are different.
Here's an example:
Child category: Accessories
Parent category: PC
Slug: pcaccessories
Child category: Accessories
Parent category: Mac
Slug: macaccessories
It is related to a previously reported ticket (#6542) which was closed, siting a "duplicate" but it is not a duplicate issue as slugs are unique, yet it complains.
I recommend that the code in Changeset #7336 (http://core.trac.wordpress.org/changeset/7336) not check for the existence of an identical category but rather, an identical slug.
(By the way, I'm using the latest stable release, 2.7.1)
Change History (8)
#2
in reply to:
↑ 1
;
follow-up:
↓ 3
@
16 years ago
Replying to zeronex:
I tried using an unique slug but it didn't work at least not when creating a new one.
I haven't tried "editing" an existing one though.
instead, I ended up making a minor "adjustment" in admin-ajax.php, line 312
if ( category_exists( trim( $_POST['cat_name'] ) ) ) { $x = new WP_Ajax_Response( array( 'what' => 'cat', 'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ), ) ); $x->send(); }
to
if ( !empty(get_category_by_slug(trim( $_POST['category_nicename']))->cat_name) ) { $x = new WP_Ajax_Response( array( 'what' => 'cat', 'id' => new WP_Error( 'cat_exists', __('The category you are trying to create has a slug that already exists. Please use an unique slug.' ), array( 'form-field' => 'cat_name' ) ), ) ); $x->send(); }
it basically uses the slug instead and checks to see if it can get a category from it (it might be better to change it to check if a cat_id is non-empty instead of cat_name)
#3
in reply to:
↑ 2
;
follow-up:
↓ 4
@
16 years ago
Replying to mofoq:
Replying to zeronex:
I tried using an unique slug but it didn't work at least not when creating a new one.
I haven't tried "editing" an existing one though.
instead, I ended up making a minor "adjustment" in admin-ajax.php, line 312
if ( category_exists( trim( $_POST['cat_name'] ) ) ) { $x = new WP_Ajax_Response( array( 'what' => 'cat', 'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ), ) ); $x->send(); }to
if ( !empty(get_category_by_slug(trim( $_POST['category_nicename']))->cat_name) ) { $x = new WP_Ajax_Response( array( 'what' => 'cat', 'id' => new WP_Error( 'cat_exists', __('The category you are trying to create has a slug that already exists. Please use an unique slug.' ), array( 'form-field' => 'cat_name' ) ), ) ); $x->send(); }it basically uses the slug instead and checks to see if it can get a category from it (it might be better to change it to check if a cat_id is non-empty instead of cat_name)
I think categories with similar name should only be allowed if the parents are different and have different slugs. Well even if slugs are same URL will be different.
#4
in reply to:
↑ 3
@
16 years ago
Replying to zeronex:
I think categories with similar name should only be allowed if the parents are different and have different slugs. Well even if slugs are same URL will be different.
I agree, but I was just a tad too lazy to implement that fully :p
I hope that the full fix that gets implemented does just this.
One thing I do foresee is the possible conflicts with some internal functions that rely solely on the cat_name instead of the ID (for instance: get_cat_ID() ).
#5
follow-up:
↓ 6
@
16 years ago
Just a thought: what were to happen if you were to edit one of these categories and change it's parent so a collision occurred?
#6
in reply to:
↑ 5
@
16 years ago
Replying to Viper007Bond:
Just a thought: what were to happen if you were to edit one of these categories and change it's parent so a collision occurred?
You have a good point but I think no one would like this bug, so similar checks should be in place when creating/updating any category.
The word around http://core.trac.wordpress.org/ticket/6542#comment:2 works i.e.
But waste of time and should work at the first place if the slug and level(parent) is different.