WordPress.org

Make WordPress Core

Changeset 15426


Ignore:
Timestamp:
07/14/10 14:13:17 (5 years ago)
Author:
ryan
Message:

If category already exists, return its ID. Restores previous behavior. fixes #14067 for 3.0.1

Location:
branches/3.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-includes/taxonomy.php

    r15220 r15426  
    16311631        $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); 
    16321632        // We've got an existing term in the same taxonomy, which matches the name of the new term: 
    1633         if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && term_exists( (int) $term_id, $taxonomy ) ) { 
     1633        if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { 
    16341634            // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. 
    16351635            $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) ); 
    16361636            if ( in_array($name, $siblings) ) { 
    1637                 return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.')); 
     1637                return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']); 
    16381638            } else { 
    16391639                $slug = wp_unique_term_slug($slug, (object) $args); 
     
    16481648                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 
    16491649            $term_id = (int) $wpdb->insert_id; 
    1650         } elseif ( term_exists( (int) $term_id, $taxonomy ) )  { 
     1650        } elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) )  { 
    16511651            // Same name, same slug. 
    1652             return new WP_Error('term_exists', __('A term with the name provided already exists.')); 
     1652            return new WP_Error('term_exists', __('A term with the name provided already exists.'), $exists['term_id']); 
    16531653        } 
    16541654    } else { 
  • branches/3.0/xmlrpc.php

    r14418 r15426  
    934934        ); 
    935935 
    936         $cat_id = wp_insert_category($new_category); 
    937         if ( !$cat_id ) 
     936        $cat_id = wp_insert_category($new_category, true); 
     937        if ( is_wp_error( $cat_id ) ) { 
     938            if ( 'term_exists' == $cat_id->get_error_code() ) 
     939                return (int) $cat_id->get_error_data(); 
     940            else 
     941                return(new IXR_Error(500, __("Sorry, the new category failed."))); 
     942        } elseif ( ! $cat_id ) { 
    938943            return(new IXR_Error(500, __("Sorry, the new category failed."))); 
     944        } 
    939945 
    940946        return($cat_id); 
Note: See TracChangeset for help on using the changeset viewer.