WordPress.org

Make WordPress Core

Ticket #17689: non-alnum-terms.diff

File non-alnum-terms.diff, 1.2 KB (added by wonderboymusic, 6 years ago)
  • wp-includes/taxonomy.php

     
    20522052        $name = stripslashes($name);
    20532053        $description = stripslashes($description);
    20542054
    2055         if ( empty($slug) )
    2056                 $slug = sanitize_title($name);
     2055        if ( empty( $slug ) ) {
     2056                $name = trim( $name );
     2057               
     2058                // check for a term like "$$$" so it isn't repeatedly added
     2059                if ( preg_match_all( '#[^:alnum:]#', $name, $matches ) && count( $matches[0] ) === strlen( $name ) ) {
     2060                        $exists = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, slug FROM $wpdb->terms WHERE name = %s", $name ) );
     2061                        if ( ! empty( $exists ) ) {
     2062                                if ( term_exists( $exists->term_id, $taxonomy ) )
     2063                                        return new WP_Error( 'term_exists', __( 'A term with the name provided already exists.' ) );
     2064                               
     2065                                // use the existing slug or the term will never match in term_exists
     2066                                $slug = $exists->slug;
     2067                        }
    20572068
     2069                } else {
     2070                        $slug = sanitize_title( $name );
     2071                }
     2072        }
     2073
    20582074        $term_group = 0;
    20592075        if ( $alias_of ) {
    20602076                $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );