WordPress.org

Make WordPress Core

Ticket #20783: 20783.2.diff

File 20783.2.diff, 2.6 KB (added by coffee2code, 22 months ago)

Updated patch to better align with wp_unique_post_slug()

  • wp-includes/taxonomy.php

     
    22332233 * @subpackage Taxonomy 
    22342234 * @since 2.3.0 
    22352235 * @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. 
    22362245 * 
    22372246 * @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 too 
     2247 * @param object $term The term object that the $slug will belong to 
    22392248 * @return string Will return a true unique slug. 
    22402249 */ 
    22412250function wp_unique_term_slug($slug, $term) { 
    22422251        global $wpdb; 
    22432252 
     2253        $override_slug = apply_filters( 'pre_wp_unique_term_slug', '', $slug, $term ); 
     2254        if ( $override_slug ) 
     2255                return $override_slug; 
     2256 
    22442257        if ( ! term_exists( $slug ) ) 
    22452258                return $slug; 
    22462259 
     2260        $original_slug = $slug; 
     2261 
    22472262        // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 
    22482263        // 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 ) ) { 
    22502265                $the_parent = $term->parent; 
    22512266                while ( ! empty($the_parent) ) { 
    22522267                        $parent_term = get_term($the_parent, $term->taxonomy); 
     
    22542269                                break; 
    22552270                        $slug .= '-' . $parent_term->slug; 
    22562271                        if ( ! term_exists( $slug ) ) 
    2257                                 return $slug; 
     2272                                return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug ); 
    22582273 
    22592274                        if ( empty($parent_term->parent) ) 
    22602275                                break; 
     
    22682283        else 
    22692284                $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); 
    22702285 
    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 ) ) { 
    22722287                $num = 2; 
    22732288                do { 
    22742289                        $alt_slug = $slug . "-$num"; 
     
    22782293                $slug = $alt_slug; 
    22792294        } 
    22802295 
    2281         return $slug; 
     2296        return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug ); 
    22822297} 
    22832298 
    22842299/**