mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-09 18:08:09 +01:00
Prevent Terms from being created in multiple taxonomies. If a slug is provided by the user, error out if it exists, else make the auto slug unique. See #11838
git-svn-id: http://svn.automattic.com/wordpress/trunk@13087 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c9ea3a7686
commit
d5eac90642
@ -1436,6 +1436,8 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
|
|||||||
|
|
||||||
if ( empty($slug) )
|
if ( empty($slug) )
|
||||||
$slug = sanitize_title($name);
|
$slug = sanitize_title($name);
|
||||||
|
elseif ( is_term($slug) ) // Provided slug issue.
|
||||||
|
return new WP_Error('term_slug_exists', __('A Term with the slug provided already exists.'));
|
||||||
|
|
||||||
$term_group = 0;
|
$term_group = 0;
|
||||||
if ( $alias_of ) {
|
if ( $alias_of ) {
|
||||||
@ -1452,7 +1454,9 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $term_id = is_term($slug) ) {
|
if ( ! $term_id = is_term($slug, $taxonomy) ) {
|
||||||
|
// Make sure the slug is unique accross all taxonomies.
|
||||||
|
$slug = wp_unique_term_slug($slug, (object) $args);
|
||||||
if ( !is_multisite() ) {
|
if ( !is_multisite() ) {
|
||||||
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
|
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
|
||||||
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
|
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
|
||||||
|
Loading…
Reference in New Issue
Block a user