From b806668e7110dc339a705785484abbb0161bb542 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 22 Dec 2014 15:33:25 +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. Fixes #30780 for trunk. Built from https://develop.svn.wordpress.org/trunk@30985 git-svn-id: http://core.svn.wordpress.org/trunk@30971 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 7d49a543e7..eca8c61156 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']) )