Changeset 32837
- Timestamp:
- 06/18/2015 01:19:12 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r32813 r32837 3325 3325 * 3326 3326 * @param string $slug The string that will be tried for a unique slug. 3327 * @param object $term The term object that the $slug will belong too.3327 * @param object $term The term object that the `$slug` will belong to. 3328 3328 * @return string Will return a true unique slug. 3329 3329 */ … … 3331 3331 global $wpdb; 3332 3332 3333 if ( ! term_exists( $slug ) )3334 return$slug;3333 $needs_suffix = true; 3334 $original_slug = $slug; 3335 3335 3336 3336 // As of 4.1, duplicate slugs are allowed as long as they're in different taxonomies. 3337 if ( get_option( 'db_version' ) >= 30133 && ! get_term_by( 'slug', $slug, $term->taxonomy ) ) {3338 return $slug;3337 if ( ! term_exists( $slug ) || get_option( 'db_version' ) >= 30133 && ! get_term_by( 'slug', $slug, $term->taxonomy ) ) { 3338 $needs_suffix = false; 3339 3339 } 3340 3340 … … 3343 3343 * by incorporating parent slugs. 3344 3344 */ 3345 if ( is_taxonomy_hierarchical($term->taxonomy) && !empty($term->parent) ) { 3345 $parent_suffix = ''; 3346 if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) { 3346 3347 $the_parent = $term->parent; 3347 3348 while ( ! empty($the_parent) ) { … … 3349 3350 if ( is_wp_error($parent_term) || empty($parent_term) ) 3350 3351 break; 3351 $slug .= '-' . $parent_term->slug; 3352 if ( ! term_exists( $slug ) ) 3353 return $slug; 3352 $parent_suffix .= '-' . $parent_term->slug; 3353 if ( ! term_exists( $slug . $parent_suffix ) ) { 3354 break; 3355 } 3354 3356 3355 3357 if ( empty($parent_term->parent) ) … … 3360 3362 3361 3363 // If we didn't get a unique slug, try appending a number to make it unique. 3362 if ( ! empty( $term->term_id ) ) 3363 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); 3364 else 3365 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); 3366 3367 if ( $wpdb->get_var( $query ) ) { 3368 $num = 2; 3369 do { 3370 $alt_slug = $slug . "-$num"; 3371 $num++; 3372 $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) ); 3373 } while ( $slug_check ); 3374 $slug = $alt_slug; 3375 } 3376 3377 return $slug; 3364 /** 3365 * Filter whether the proposed unique term slug is bad. 3366 * 3367 * @since 4.3.0 3368 * 3369 * @param bool $needs_suffix Whether the slug needs to be made unique with a suffix. 3370 * @param string $slug The slug. 3371 * @param object $term Term object. 3372 */ 3373 if ( apply_filters( 'wp_unique_term_slug_is_bad_slug', $needs_suffix, $slug, $term ) ) { 3374 if ( $parent_suffix ) { 3375 $slug .= $parent_suffix; 3376 } else { 3377 if ( ! empty( $term->term_id ) ) 3378 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); 3379 else 3380 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); 3381 3382 if ( $wpdb->get_var( $query ) ) { 3383 $num = 2; 3384 do { 3385 $alt_slug = $slug . "-$num"; 3386 $num++; 3387 $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) ); 3388 } while ( $slug_check ); 3389 $slug = $alt_slug; 3390 } 3391 } 3392 } 3393 3394 /** 3395 * Filter the unique term slug. 3396 * 3397 * @since 4.3.0 3398 * 3399 * @param string $slug Unique term slug. 3400 * @param object $term Term object. 3401 * @param string $original_slug Slug originally passed to the function for testing. 3402 */ 3403 return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug ); 3378 3404 } 3379 3405
Note: See TracChangeset
for help on using the changeset viewer.