WordPress.org

Make WordPress Core

Ticket #17689: 17689.2.diff

File 17689.2.diff, 2.0 KB (added by wonderboymusic, 5 years ago)
  • wp-includes/taxonomy.php

     
    20652065        $name = stripslashes($name);
    20662066        $description = stripslashes($description);
    20672067
    2068         if ( empty($slug) )
    2069                 $slug = sanitize_title($name);
     2068        if ( empty( $slug ) ) {
     2069                $name = trim( $name );
    20702070
     2071                // check for a term like "$$$" so it isn't repeatedly added
     2072                if ( preg_match_all( '#[^a-zA-Z0-9]#', $name, $matches ) && count( $matches[0] ) === strlen( $name ) ) {
     2073                        $exists = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, slug FROM $wpdb->terms WHERE name = %s", $name ) );
     2074                        if ( ! empty( $exists ) ) {
     2075                                if ( term_exists( $exists->term_id, $taxonomy ) )
     2076                                        return new WP_Error( 'term_exists', __( 'A term with the name provided already exists.' ) );
     2077
     2078                                // use the existing slug or the term will never match in term_exists
     2079                                $slug = $exists->slug;
     2080                        }
     2081
     2082                } else {
     2083                        $slug = sanitize_title( $name );
     2084                }
     2085        }
     2086
    20712087        $term_group = 0;
    20722088        if ( $alias_of ) {
    20732089                $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );
  • wp-includes/formatting.php

     
    980980                $title = utf8_uri_encode($title, 200);
    981981        }
    982982
     983        // let's assume that "+" next to a char followed by a space is not entered as space but as "plus"
     984        // and that "-" directly next to a char followed by a space is not a dash but is "minus"
     985        $title = preg_replace( array( '#([^-])-\s#', '#([^-])-$#' ), array( '$1-minus ', '$1-minus' ), $title );
     986        $title = preg_replace( array( '#([^+])\+\s#', '#([^+])\+$#' ), array( '$1-plus ', '$1-plus' ), $title );
     987
    983988        $title = strtolower($title);
    984989        $title = preg_replace('/&.+?;/', '', $title); // kill entities
    985990        $title = str_replace('.', '-', $title);