Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#13060 closed defect (bug) (fixed)

Duplicate Term bug

Reported by: deannas's profile DeannaS Owned by: dd32's profile dd32
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: needs-patch
Focuses: Cc:

Description

There's a bug in the taxonomy edit pages (/wp-admin/edit-tags.php). If you try to add a term that already exists, the following errors are thrown and display in a red box at the top of the page:

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/xxx/wp-includes/wp-db.php on line 772

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/xxx/wp-includes/wp-db.php on line 772

Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/wp-includes/wp-db.php:772) in /home/juwcoope/public_html/wp3/wp-includes/classes.php on line 1697

I think the fix is to edit wp-includes\taxonomy.php on lines 1526/1527 like so:

//elseif ( is_term($slug, $taxonomy) ) // Provided slug issue.
	if (is_term($slug, $taxonomy) )
		return new WP_Error('term_slug_exists', __('A Term with the slug provided already exists.'));


Change History (9)

#1 @ocean90
14 years ago

  • Component changed from General to Taxonomy
  • Milestone changed from Unassigned to 3.0
  • Owner set to filosofo
  • Version set to 3.0

#2 @scribu
14 years ago

  • Keywords reporter-feedback added

Can't reproduce. Attempting to add a duplicate term does nothing.

Try disabling all plugins.

#3 @nacin
14 years ago

  • Keywords needs-patch added; reporter-feedback removed
  • Owner changed from filosofo to dd32
  • Status changed from new to assigned

dd32 and I have talked about this bug. Neither of us ended up creating a ticket yet (oops) but it's on both of our to-do lists. I'm actually surprised it's taken this long for someone else to notice it.

Steps to reproduce:

  1. Add a category called 'apple'. Don't give it a slug or anything.
  1. Repeat step 1. Should blow up with mysql_real_escape_string() errors.

How to fix:

  1. Line 1548. $term_id = is_term( $term ) was changed to is_term( $term, $tax ) in r13087. When is_term() is given a taxonomy, it decides to return an object instead of just a term ID. Easy fix, one of which would be to rename $term_id to $_term there and add an else to the end, in which we set $term_id = $_termterm_id?.
  1. Once that is fixed, try the steps to reproduce again. You'll end up with another row being added to the table to the left, exactly identical. The database is untouched. This is because wp_insert_term() returns an array (not WP_Error) when the term/slug/taxonomy combo already exists. admin-ajax.php doesn't account for that, either as a return value, or beforehand. (2.9 used category_exists, i.e. is_term...)

#4 @dd32
14 years ago

  • Status changed from assigned to accepted

You'll end up with another row being added to the table to the left, exactly identical. The database is untouched. This is because wp_insert_term() returns an array (not WP_Error) when the term/slug/taxonomy combo already exists. admin-ajax.php doesn't account for that, either as a return value, or beforehand. (2.9 used category_exists, i.e. is_term...)

This behaviour is the same in 2.9 for post tags, You add one that already exists, and you get an extra row added to the table, yet the database is untouched. Categories now suffer from it since it was merged into the same table.

For both Categories and tags, 2.9 acted strangely when adding a new term with a slug, For example, if you had {slug => red, name => Red} in the database already, and you added {slug => red, name => "Red Hats"} , You'd loose the "Red Hats" name, and it'd re-use the "Red" name.

#5 @dd32
14 years ago

(In [14229]) Allow Terms to exist within multiple taxonomies (Regression in 3.0); If a term slug is provided on the form, Respect it (do not suffix it, instead, feedback with error); Do not allow hierarchical term names to exist multiple times within a set level (ie. AU/NSW + AU/NSW is bad, AU/NSW + AU/VIC + AU/VIC/NSW is ok). See #13060

#6 @ryan
14 years ago

Just a reminder to all to remember to test taxonomy changes with global terms and multisite. I haven't noticed any problems yet, just a reminder. See also #10712"

#7 @ryan
14 years ago

Fixed?

#8 @ryan
14 years ago

See also #13481 and #13119

#9 @ryan
14 years ago

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

I think we have this handled now. Please test and re-open if problems persist.

Note: See TracTickets for help on using tickets.