From 7ba6f5dfd45eff516e538894554d5efc5305068b Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 9 Feb 2015 03:59:21 +0000 Subject: [PATCH] In `wp_update_term()`, limit duplicate slug checks to the same taxonomy as the updated term. In 4.1 [30240], `wp_insert_term()` was modified to allow the creation of terms with duplicate slugs, as long as the terms are in different taxonomies. `wp_update_term()` didn't get the corresponding modification, with the result that term updates fail when the term being updated shares a slug with an older term, regardless of that older term's taxonomy. Props ipm-frommen. Merges [30985] to the 4.1 branch. Fixes #30780. Built from https://develop.svn.wordpress.org/branches/4.1@31378 git-svn-id: http://core.svn.wordpress.org/branches/4.1@31359 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 099d236618..7daf333850 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -3353,8 +3353,8 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { $parent = apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args ); // Check for duplicate slug - $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) ); - if ( $id && ($id != $term_id) ) { + $duplicate = get_term_by( 'slug', $slug, $taxonomy ); + if ( $duplicate && $duplicate->term_id != $term_id ) { // If an empty slug was passed or the parent changed, reset the slug to something unique. // Otherwise, bail. if ( $empty_slug || ( $parent != $term['parent']) )