WordPress.org

Make WordPress Core

Ticket #30780: 30780.patch

File 30780.patch, 1.9 KB (added by ipm-frommen, 6 years ago)
  • wp-includes/taxonomy.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    33523352         */
    33533353        $parent = apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args );
    33543354
    3355         // Check for duplicate slug
    3356         $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );
    3357         if ( $id && ($id != $term_id) ) {
    3358                 // If an empty slug was passed or the parent changed, reset the slug to something unique.
    3359                 // Otherwise, bail.
    3360                 if ( $empty_slug || ( $parent != $term['parent']) )
    3361                         $slug = wp_unique_term_slug($slug, (object) $args);
    3362                 else
    3363                         return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
     3355        // Terms with duplicate names are not allowed at the same level of a taxonomy hierarchy.
     3356        if ( $exists = term_exists( $slug, $taxonomy ) ) {
     3357                $existing_term = get_term( $exists['term_id'], $taxonomy );
     3358
     3359                if ( $name === $existing_term->name ) {
     3360
     3361                        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
     3362                                $siblings = get_terms( $taxonomy, array( 'fields' => 'names', 'get' => 'all', 'parent' => $parent ) );
     3363                                if ( in_array( $name, $siblings ) ) {
     3364                                        return new WP_Error( 'term_exists', __( 'A term with the name and slug already exists with this parent.' ), $exists['term_id'] );
     3365                                }
     3366
     3367                        } else {
     3368                                return new WP_Error( 'term_exists', __( 'A term with the name and slug already exists in this taxonomy.' ), $exists['term_id'] );
     3369                        }
     3370                }
    33643371        }
    33653372
    33663373        $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );