Ticket #20783: 20783.2.diff
| File 20783.2.diff, 2.6 KB (added by , 14 years ago) |
|---|
-
wp-includes/taxonomy.php
2233 2233 * @subpackage Taxonomy 2234 2234 * @since 2.3.0 2235 2235 * @uses $wpdb 2236 * @uses apply_filters() Calls 'pre_wp_unique_term_slug' with empty string and 2237 * all function arguments 2238 * @uses apply_filters() Will call the 'wp_unique_term_slug_is_bad_hierarchical_slug' 2239 * filter and pass false and all function arguments 2240 * @uses apply_filters() Will call the 'wp_unique_term_slug_is_bad_flat_slug' 2241 * filter and pass false, the potentially modified slug, the term, and the 2242 * original slug. 2243 * @uses apply_filters() Will call the 'wp_unique_term_slug' filter and pass 2244 * the resulting unique slug, the term, and the original slug. 2236 2245 * 2237 2246 * @param string $slug The string that will be tried for a unique slug 2238 * @param object $term The term object that the $slug will belong to o2247 * @param object $term The term object that the $slug will belong to 2239 2248 * @return string Will return a true unique slug. 2240 2249 */ 2241 2250 function wp_unique_term_slug($slug, $term) { 2242 2251 global $wpdb; 2243 2252 2253 $override_slug = apply_filters( 'pre_wp_unique_term_slug', '', $slug, $term ); 2254 if ( $override_slug ) 2255 return $override_slug; 2256 2244 2257 if ( ! term_exists( $slug ) ) 2245 2258 return $slug; 2246 2259 2260 $original_slug = $slug; 2261 2247 2262 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 2248 2263 // by incorporating parent slugs. 2249 if ( is_taxonomy_hierarchical( $term->taxonomy) && !empty($term->parent) ) {2264 if ( is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) && ! apply_filters( 'wp_unique_term_slug_is_bad_hierarchical_slug', false, $slug, $term ) ) { 2250 2265 $the_parent = $term->parent; 2251 2266 while ( ! empty($the_parent) ) { 2252 2267 $parent_term = get_term($the_parent, $term->taxonomy); … … 2254 2269 break; 2255 2270 $slug .= '-' . $parent_term->slug; 2256 2271 if ( ! term_exists( $slug ) ) 2257 return $slug;2272 return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug ); 2258 2273 2259 2274 if ( empty($parent_term->parent) ) 2260 2275 break; … … 2268 2283 else 2269 2284 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); 2270 2285 2271 if ( $wpdb->get_var( $query ) ) {2286 if ( $wpdb->get_var( $query ) || apply_filters( 'wp_unique_term_slug_is_bad_flat_slug', false, $slug, $term, $original_slug ) ) { 2272 2287 $num = 2; 2273 2288 do { 2274 2289 $alt_slug = $slug . "-$num"; … … 2278 2293 $slug = $alt_slug; 2279 2294 } 2280 2295 2281 return $slug;2296 return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug ); 2282 2297 } 2283 2298 2284 2299 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)