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.


git-svn-id: https://develop.svn.wordpress.org/trunk@28733 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2014-06-11 02:27:36 +00:00
parent 1b07af046f
commit eadc17c4f9
2 changed files with 69 additions and 1 deletions
+7 -1
View File
@@ -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'];
}