WordPress.org

Make WordPress Core

Ticket #17689: 17689.get-term-by-name.diff

File 17689.get-term-by-name.diff, 746 bytes (added by SergeyBiryukov, 6 years ago)
  • src/wp-includes/taxonomy.php

     
    20892089        $name = wp_unslash($name);
    20902090        $description = wp_unslash($description);
    20912091
    2092         if ( empty($slug) )
    2093                 $slug = sanitize_title($name);
     2092        $name = trim( $name );
    20942093
     2094        if ( empty( $slug ) ) {
     2095                $existing_term = get_term_by( 'name', $name, $taxonomy );
     2096                if ( $existing_term )
     2097                        $slug = $existing_term->slug;
     2098                else
     2099                        $slug = sanitize_title( $name );
     2100        }
     2101
    20952102        $term_group = 0;
    20962103        if ( $alias_of ) {
    20972104                $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );