From 980744f8822db4dea818c2f6495b6ea5f4386ede Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 11 Jun 2014 02:28:14 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@28733 git-svn-id: http://core.svn.wordpress.org/trunk@28547 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index ae0ef81dd3..1c48934ae9 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2436,7 +2436,13 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $slug_provided = ! empty( $args['slug'] ); if ( ! $slug_provided ) { - $slug = sanitize_title($name); + $_name = trim( $name ); + $existing_term = get_term_by( 'name', $_name, $taxonomy ); + if ( $existing_term ) { + $slug = $existing_term->slug; + } else { + $slug = sanitize_title( $name ); + } } else { $slug = $args['slug']; }