From de88d303fae6fe4649e13dce29b52a4d74e01d97 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 13 Feb 2010 05:52:27 +0000 Subject: [PATCH] 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: https://develop.svn.wordpress.org/trunk@13087 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 9eb4329b87..af610185cf 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1436,6 +1436,8 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( empty($slug) ) $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; 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 ( 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);