Ticket #18448: 18448.patch.diff
File 18448.patch.diff, 6.7 KB (added by , 14 years ago) |
---|
-
wp-includes/taxonomy.php
1968 1968 * @param string $term The term to add or update. 1969 1969 * @param string $taxonomy The taxonomy to which to add the term 1970 1970 * @param array|string $args Change the values of the inserted term 1971 * @param bool $wp_error Allow to return WP_Error or not 1971 1972 * @return array|WP_Error The Term ID and Term Taxonomy ID 1972 1973 */ 1973 function wp_insert_term( $term, $taxonomy, $args = array() ) {1974 function wp_insert_term( $term, $taxonomy, $args = array(), $wp_error = true ) { 1974 1975 global $wpdb; 1975 1976 1976 1977 if ( ! taxonomy_exists($taxonomy) ) 1977 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1978 if($wp_error) { 1979 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1980 } else { 1981 return array('term_id' => 0, 'term_taxonomy_id' => 0); 1982 } 1978 1983 1979 1984 $term = apply_filters( 'pre_insert_term', $term, $taxonomy ); 1980 1985 if ( is_wp_error( $term ) ) 1981 1986 return $term; 1982 1987 1983 1988 if ( is_int($term) && 0 == $term ) 1984 return new WP_Error('invalid_term_id', __('Invalid term ID')); 1989 if($wp_error) { 1990 return new WP_Error('invalid_term_id', __('Invalid term ID')); 1991 } else { 1992 return array('term_id' => 0, 'term_taxonomy_id' => 0); 1993 } 1985 1994 1986 1995 if ( '' == trim($term) ) 1987 return new WP_Error('empty_term_name', __('A name is required for this term')); 1996 if($wp_error) { 1997 return new WP_Error('empty_term_name', __('A name is required for this term')); 1998 } else { 1999 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2000 } 1988 2001 1989 2002 $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); 1990 2003 $args = wp_parse_args($args, $defaults); … … 2026 2039 } else { 2027 2040 $slug = wp_unique_term_slug($slug, (object) $args); 2028 2041 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 2029 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2042 if($wp_error) { 2043 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2044 } else { 2045 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2046 } 2030 2047 $term_id = (int) $wpdb->insert_id; 2031 2048 } 2032 2049 } elseif ( $existing_term['name'] != $name ) { 2033 2050 // We've got an existing term, with a different name, Create the new term. 2034 2051 $slug = wp_unique_term_slug($slug, (object) $args); 2035 2052 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 2036 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2053 if($wp_error) { 2054 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2055 } else { 2056 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2057 } 2037 2058 $term_id = (int) $wpdb->insert_id; 2038 2059 } elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) ) { 2039 2060 // Same name, same slug. 2040 return new WP_Error('term_exists', __('A term with the name provided already exists.'), $exists['term_id']); 2061 if($wp_error) { 2062 return new WP_Error('term_exists', __('A term with the name provided already exists.'), $exists['term_id']); 2063 } else { 2064 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2065 } 2041 2066 } 2042 2067 } else { 2043 2068 // This term does not exist at all in the database, Create it. 2044 2069 $slug = wp_unique_term_slug($slug, (object) $args); 2045 2070 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 2046 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2071 if($wp_error) { 2072 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2073 } else { 2074 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2075 } 2047 2076 $term_id = (int) $wpdb->insert_id; 2048 2077 } 2049 2078 … … 2270 2299 * @param int $term_id The ID of the term 2271 2300 * @param string $taxonomy The context in which to relate the term to the object. 2272 2301 * @param array|string $args Overwrite term field values 2302 * @param bool $wp_error Allow to return WP_Error or not 2273 2303 * @return array|WP_Error Returns Term ID and Taxonomy Term ID 2274 2304 */ 2275 function wp_update_term( $term_id, $taxonomy, $args = array() ) {2305 function wp_update_term( $term_id, $taxonomy, $args = array(), $wp_error = true ) { 2276 2306 global $wpdb; 2277 2307 2278 2308 if ( ! taxonomy_exists($taxonomy) ) 2279 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 2309 if($wp_error) { 2310 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 2311 } else { 2312 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2313 } 2280 2314 2281 2315 $term_id = (int) $term_id; 2282 2316 … … 2302 2336 $description = stripslashes($description); 2303 2337 2304 2338 if ( '' == trim($name) ) 2305 return new WP_Error('empty_term_name', __('A name is required for this term')); 2339 if($wp_error) { 2340 return new WP_Error('empty_term_name', __('A name is required for this term')); 2341 } else { 2342 return array('term_id' => 0, 'term_taxonomy_id' => 0);; 2343 } 2306 2344 2307 2345 $empty_slug = false; 2308 2346 if ( empty($slug) ) { … … 2335 2373 if ( $empty_slug || ( $parent != $term['parent']) ) 2336 2374 $slug = wp_unique_term_slug($slug, (object) $args); 2337 2375 else 2338 return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); 2376 if($wp_error) { 2377 return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); 2378 } else { 2379 return array('term_id' => 0, 'term_taxonomy_id' => 0); 2380 } 2339 2381 } 2340 2382 do_action( 'edit_terms', $term_id ); 2341 2383 $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); -
wp-admin/includes/taxonomy.php
51 51 if ( $id = category_exists($cat_name, $parent) ) 52 52 return $id; 53 53 54 return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) ); 54 $cat = wp_insert_term( $cat_name, 'category', array('name' => $name, 'parent' => $parent), false ); 55 return $cat['term_id']; 55 56 } 56 57 57 58 /** … … 162 163 163 164 // Merge old and new fields with new fields overwriting old ones. 164 165 $catarr = array_merge($category, $catarr); 166 167 $cat = wp_update_term( $catarr['cat_ID'], 'category', array('name' => $catarr['cat_name'], 'slug' => $catarr['category_nicename'], 'parent' => $catarr['category_parent'], 'description' => $catarr['category_description']), false); 165 168 166 return wp_insert_category($catarr);169 return $cat['term_id']; 167 170 } 168 171 169 172 //