﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
20783	Add filter to wp_unique_term_slug()	bolo1988		"I can't modify the result of wp_unique_term_slug(), but if using the following code:

{{{
function wp_unique_term_slug($slug, $term) {
	global $wpdb;

	if ( ! term_exists( $slug ) )
		return $slug;

	// If the taxonomy supports hierarchy and the term has a parent, make the slug unique
	// by incorporating parent slugs.
	if ( is_taxonomy_hierarchical($term->taxonomy) && !empty($term->parent) ) {
		$the_parent = $term->parent;
		while ( ! empty($the_parent) ) {
			$parent_term = get_term($the_parent, $term->taxonomy);
			if ( is_wp_error($parent_term) || empty($parent_term) )
				break;
			$slug .= '-' . $parent_term->slug;
			if ( ! term_exists( $slug ) )
				return $slug;

			if ( empty($parent_term->parent) )
				break;
			$the_parent = $parent_term->parent;
		}
	}

	// If we didn't get a unique slug, try appending a number to make it unique.
	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"", $slug );

	if ( $wpdb->get_var( $query ) ) {
		$num = 2;
		do {
			$alt_slug = $slug . ""-$num"";
			$num++;
			$slug_check = $wpdb->get_var( $wpdb->prepare( ""SELECT slug FROM $wpdb->terms WHERE slug = %s"", $alt_slug ) );
		} while ( $slug_check );
		$slug = $alt_slug;
	}

	return apply_filters('unique_term_slug', $slug);
}

}}}
"	enhancement	new	normal	Awaiting Review	Taxonomy	3.3.2	normal		has-patch dev-feedback needs-testing	travis@…
