Make WordPress Core

Changeset 14229


Ignore:
Timestamp:
04/25/2010 07:35:16 AM (16 years ago)
Author:
dd32
Message:

Allow Terms to exist within multiple taxonomies (Regression in 3.0); If a term slug is provided on the form, Respect it (do not suffix it, instead, feedback with error); Do not allow hierarchical term names to exist multiple times within a set level (ie. AU/NSW + AU/NSW is bad, AU/NSW + AU/VIC + AU/VIC/NSW is ok). See #13060

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r14214 r14229  
    573573                        $level++;
    574574                }
    575         }
    576         if ( is_taxonomy_hierarchical($taxonomy) )
    577575                $noparents = _tag_row( $tag, $level, $taxonomy );
     576        }
    578577        $tag->name = $tag_full_name;
    579578        $parents = _tag_row( $tag, 0, $taxonomy);
  • trunk/wp-includes/taxonomy.php

    r14108 r14229  
    15241524        if ( empty($slug) )
    15251525                $slug = sanitize_title($name);
    1526         elseif ( is_term($slug, $taxonomy) ) // Provided slug issue.
    1527                 return new WP_Error('term_slug_exists', __('A Term with the slug provided already exists.'));
     1526        elseif ( is_term($slug) )
     1527                return new WP_Error('term_slug_exists', __('A term with the slug provided already exists.'));
    15281528
    15291529        $term_group = 0;
    … …  
    15421542        }
    15431543
    1544         if ( ! $term_id = is_term($slug, $taxonomy) ) {
    1545                 // Make sure the slug is unique accross all taxonomies.
     1544        if ( $term_id = is_term($slug) ) {
     1545                $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
     1546                // We've got an existing term, which matches the name of the new term:
     1547                if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name ) {
     1548                        // Heirarchical, and it matches an existing term, Do not allow same "name" in the same level.
     1549                        $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );
     1550                        if ( in_array($name, $siblings) ) {
     1551                                return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'));
     1552                        } else {
     1553                                $slug = wp_unique_term_slug($slug, (object) $args);
     1554                                if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
     1555                                        return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
     1556                                $term_id = (int) $wpdb->insert_id;
     1557                        }
     1558                } elseif ( $existing_term['name'] != $name ) {
     1559                        // We've got an existing term, with a different name, Creat ethe new term.
     1560                        $slug = wp_unique_term_slug($slug, (object) $args);
     1561                        if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
     1562                                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
     1563                        $term_id = (int) $wpdb->insert_id;
     1564                }
     1565        } else {
     1566                // This term does not exist at all in the database, Create it.
    15461567                $slug = wp_unique_term_slug($slug, (object) $args);
    15471568                if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
    15481569                        return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
    15491570                $term_id = (int) $wpdb->insert_id;
    1550         } else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) {
    1551                 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique
    1552                 // by incorporating parent slugs.
    1553                 $slug = wp_unique_term_slug($slug, (object) $args);
    1554                 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
    1555                         return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
    1556                 $term_id = (int) $wpdb->insert_id;
    1557         }
    1558 
    1559         if ( empty($slug) ) {
     1571        }
     1572
     1573        // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string.
     1574        if ( empty($slug) ) {
    15601575                $slug = sanitize_title($slug, $term_id);
    15611576                do_action( 'edit_terms', $term_id );
Note: See TracChangeset for help on using the changeset viewer.