Ticket #22400: 22400.taxonomy.php.diff
File 22400.taxonomy.php.diff, 2.3 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/taxonomy.php
90 90 */ 91 91 function wp_insert_category($catarr, $wp_error = false) { 92 92 $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => ''); 93 $catarr = wp_parse_args($catarr, $cat_defaults); 94 extract($catarr, EXTR_SKIP); 93 $catarr = wp_parse_args( $catarr, $cat_defaults ); 95 94 96 if ( trim( $cat _name) == '' ) {95 if ( trim( $catarr['cat_name'] ) == '' ) { 97 96 if ( ! $wp_error ) 98 97 return 0; 99 98 else 100 99 return new WP_Error( 'cat_name', __('You did not enter a category name.') ); 101 100 } 102 101 103 $cat _ID = (int) $cat_ID;102 $catarr['cat_ID'] = (int) $catarr['cat_ID']; 104 103 105 104 // Are we updating or creating? 106 if ( !empty ( $cat_ID) )105 if ( !empty ( $catarr['cat_ID'] ) ) 107 106 $update = true; 108 107 else 109 108 $update = false; 110 109 111 $name = $cat _name;112 $description = $cat egory_description;113 $slug = $cat egory_nicename;114 $parent = $cat egory_parent;110 $name = $catarr['cat_name']; 111 $description = $catarr['category_description']; 112 $slug = $catarr['category_nicename']; 113 $parent = $catarr['category_parent']; 115 114 116 115 $parent = (int) $parent; 117 116 if ( $parent < 0 ) 118 117 $parent = 0; 119 118 120 if ( empty( $parent ) || ! term_exists( $parent, $taxonomy ) || ( $cat _ID && term_is_ancestor_of( $cat_ID, $parent, $taxonomy) ) )119 if ( empty( $parent ) || ! term_exists( $parent, $taxonomy ) || ( $catarr['cat_ID'] && term_is_ancestor_of( $catarr['cat_ID'], $parent, $catarr['taxonomy'] ) ) ) 121 120 $parent = 0; 122 121 123 122 $args = compact('name', 'slug', 'parent', 'description'); 124 123 125 124 if ( $update ) 126 $cat _ID = wp_update_term($cat_ID, $taxonomy, $args);125 $catarr['cat_ID'] = wp_update_term( $catarr['cat_ID'], $catarr['taxonomy'], $args); 127 126 else 128 $cat _ID = wp_insert_term($cat_name, $taxonomy, $args);127 $catarr['cat_ID'] = wp_insert_term( $catarr['cat_name'], $catarr['taxonomy'], $args); 129 128 130 if ( is_wp_error( $cat_ID) ) {129 if ( is_wp_error( $catarr['cat_ID'] ) ) { 131 130 if ( $wp_error ) 132 return $cat _ID;131 return $catarr['cat_ID']; 133 132 else 134 133 return 0; 135 134 } 136 137 return $cat_ID['term_id']; 135 return $catarr['cat_ID']['term_id']; 138 136 } 139 137 140 138 /**