WordPress.org

Make WordPress Core

Changeset 15425


Ignore:
Timestamp:
07/14/2010 02:12:23 PM (8 years ago)
Author:
ryan
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r15355 r15425  
    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 {
  • trunk/xmlrpc.php

    r14418 r15425  
    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.