Opened 14 years ago
Closed 14 years ago
#13060 closed defect (bug) (fixed)
Duplicate Term bug
Reported by: | DeannaS | Owned by: | 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
@
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
#3
@
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:
- Add a category called 'apple'. Don't give it a slug or anything.
- Repeat step 1. Should blow up with mysql_real_escape_string() errors.
How to fix:
- 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?.
- 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
@
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
@
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
Can't reproduce. Attempting to add a duplicate term does nothing.
Try disabling all plugins.