WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#12349 closed defect (bug) (fixed)

wp_insert_term doesn't check for already existing slugs if the slug is implicit

Reported by: nbachiyski Owned by: dd32
Milestone: 3.0 Priority: high
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

Expected: even if the slug of the new term isn't explicitly provided, but generated from the term's name wp_insert_term() should check if it already exists.

Actual: it doesn't. wp_insert_term() checks for existing slug only of it has it explicitly given as an argument.

Attachments (2)

check-already-existsing-slug-even-if-empty.diff (491 bytes) - added by nbachiyski 8 years ago.
12439.diff (626 bytes) - added by ryan 8 years ago.

Download all attachments as: .zip

Change History (12)

#1 @dd32
8 years ago

I did that for a specific reason, At the time, I believe it was for back compat reasons. Its possible to have a Term in multiple taxonomies by having the name the same. (Ie. Create Tag "Test" and category "Test" and they'll both get 'test' slug, and the same TermID).

That branching selection, was to ensure that that was still possible if the slug was provided..

Personally.. I dont know why anyone would want that (to me) strange behaviour.

#2 @dd32
8 years ago

  • Component changed from General to Taxonomy
  • Owner set to filosofo

#3 @filosofo
8 years ago

  • Owner changed from filosofo to dd32
  • Status changed from new to assigned

#4 @nacin
8 years ago

We need to decide on this. It should match 2.9 behavior...

References: [13087], [13405], [14229].

#5 @ryan
8 years ago

With recent changes to wp_insert_term(), we may be able to remove that elseif.

#6 @ryan
8 years ago

Notably, [14783] and [14784].

#7 @ryan
8 years ago

That check does prevent the user from doing really silly things with slugs. Like creating an "Apple" tag with "apple" slug and then creating an "Orange" tag with an "apple" slug (which will end up apple-2 and two tags with the same name will appear). Perhaps a better patch is to do the dupe check only if the provided slug does not match the slug generated from the name. This way people who fill in the slug to match the name won't get a dupe error.

@ryan
8 years ago

#8 @ryan
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [14839]) Don't issue dupe slug error if provided slug matches name derived slug. fixes #12349

#9 @ryan
8 years ago

Actually, this may be responsible for some of the slug problems during import. I think the safest is to restore 2.9 behavior.

#10 @ryan
8 years ago

(In [14840]) Remove already exists check for passed in slug. fixes #12349

Note: See TracTickets for help on using tickets.