mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-18 04:25:07 +00:00
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
This commit is contained in:
parent
620e6ebe37
commit
980744f882
@ -2436,7 +2436,13 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
|
|||||||
|
|
||||||
$slug_provided = ! empty( $args['slug'] );
|
$slug_provided = ! empty( $args['slug'] );
|
||||||
if ( ! $slug_provided ) {
|
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 {
|
} else {
|
||||||
$slug = $args['slug'];
|
$slug = $args['slug'];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user