WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/11/2014 02:27:36 AM (7 years ago)
Author:
wonderboymusic
Message:

In wp_insert_term(), when no slug is provided, check for an existing term by name. If it exists, use that slug instead of calling sanitize_title( $name ).

Prevents creating an endless number of terms like A+ or $$$$ in any given taxonomy.

Props wonderboymusic, SergeyBiryukov, aaroncampbell.
Fixes #17689.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r28712 r28733  
    24372437    $slug_provided = ! empty( $args['slug'] );
    24382438    if ( ! $slug_provided ) {
    2439         $slug = sanitize_title($name);
     2439        $_name = trim( $name );
     2440        $existing_term = get_term_by( 'name', $_name, $taxonomy );
     2441        if ( $existing_term ) {
     2442            $slug = $existing_term->slug;
     2443        } else {
     2444            $slug = sanitize_title( $name );
     2445        }
    24402446    } else {
    24412447        $slug = $args['slug'];
Note: See TracChangeset for help on using the changeset viewer.