Make term slug unique when moving to another parent.

git-svn-id: http://svn.automattic.com/wordpress/trunk@6326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-11-09 18:34:41 +00:00
parent 9a94e7b26c
commit 8689aef969
1 changed files with 8 additions and 3 deletions

View File

@ -1206,7 +1206,12 @@ function wp_unique_term_slug($slug, $term) {
} }
// If we didn't get a unique slug, try appending a number to make it unique. // If we didn't get a unique slug, try appending a number to make it unique.
if ( $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ) ) ) { if ( !empty($args['term_id']) )
$query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $args['term_id'] );
else
$query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s $where", $slug );
if ( $wpdb->get_var( $query ) ) {
$num = 2; $num = 2;
do { do {
$alt_slug = $slug . "-$num"; $alt_slug = $slug . "-$num";
@ -1281,9 +1286,9 @@ function wp_update_term( $term, $taxonomy, $args = array() ) {
// Check for duplicate slug // Check for duplicate slug
$id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) ); $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );
if ( $id && ($id != $term_id) ) { if ( $id && ($id != $term_id) ) {
// If an empty slug was passed, reset the slug to something unique. // If an empty slug was passed or the parent changed, reset the slug to something unique.
// Otherwise, bail. // Otherwise, bail.
if ( $empty_slug ) if ( $empty_slug || ( $parent != $term->parent) )
$slug = wp_unique_term_slug($slug, (object) $args); $slug = wp_unique_term_slug($slug, (object) $args);
else else
return new WP_Error('duplicate_term_slug', sprintf(__('The slug "%s" is already in use by another term'), $slug)); return new WP_Error('duplicate_term_slug', sprintf(__('The slug "%s" is already in use by another term'), $slug));