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.


git-svn-id: https://develop.svn.wordpress.org/trunk@26544 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-12-02 23:05:49 +00:00
parent 2ec996d812
commit 922125f1cc
1 changed files with 9 additions and 3 deletions

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.