Be specific in term_exists error messages in wp_insert_term() as to what already exists (name, or name and slug).

props ericmann, SergeyBiryukov.
fixes #15741.

Built from https://develop.svn.wordpress.org/trunk@26544


git-svn-id: http://core.svn.wordpress.org/trunk@26436 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-12-02 23:06:11 +00:00
parent 6fa4ce2284
commit 804be8b332

View File

@ -2143,8 +2143,10 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
$name = wp_unslash($name);
$description = wp_unslash($description);
if ( empty($slug) )
$slug_provided = ! empty( $slug );
if ( ! $slug_provided ) {
$slug = sanitize_title($name);
}
$term_group = 0;
if ( $alias_of ) {
@ -2168,7 +2170,11 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
// Hierarchical, and it matches an existing term, Do not allow same "name" in the same level.
$siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );
if ( in_array($name, $siblings) ) {
return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']);
if ( $slug_provided ) {
return new WP_Error( 'term_exists', __( 'A term with the name and slug provided already exists with this parent.' ), $exists['term_id'] );
} else {
return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $exists['term_id'] );
}
} else {
$slug = wp_unique_term_slug($slug, (object) $args);
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
@ -2183,7 +2189,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
$term_id = (int) $wpdb->insert_id;
} elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) ) {
// Same name, same slug.
return new WP_Error('term_exists', __('A term with the name provided already exists.'), $exists['term_id']);
return new WP_Error( 'term_exists', __( 'A term with the name and slug provided already exists.' ), $exists['term_id'] );
}
} else {
// This term does not exist at all in the database, Create it.