Changeset 5289 for branches/2.2/wp-admin/admin-db.php
- Timestamp:
- 04/19/2007 10:26:52 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/wp-admin/admin-db.php
r5272 r5289 122 122 $links_private = 0; 123 123 124 if ( empty($type) )125 $type = TAXONOMY_CATEGORY;126 127 // Let's check if we have this category already, if so just do an update128 if ( !$update && $cat_ID = category_object_exists( $category_nicename ) )129 $update = true;130 131 124 if (!$update) { 132 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private , type) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private', '$type')");125 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')"); 133 126 $cat_ID = (int) $wpdb->insert_id; 134 127 } else { 135 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' , type = '$type'WHERE cat_ID = '$cat_ID'");128 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' WHERE cat_ID = '$cat_ID'"); 136 129 } 137 130 … … 199 192 $parent = $category->category_parent; 200 193 201 // Delete the category if it is not also a tag. 202 if ( 0 == ($category->type & TAXONOMY_TAG) ) { 203 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) 204 return 0; 205 } else { 206 $wpdb->query("UPDATE $wpdb->categories SET type = type & ~" . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_ID'"); 207 } 194 // Delete the category 195 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) 196 return 0; 197 208 198 // Update children to point to new parent 209 199 $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 210 200 211 201 // Only set posts and links to the default category if they're not in another category already 212 $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID' AND rel_type = 'category'");202 $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'"); 213 203 foreach ( (array) $posts as $post_id ) { 214 204 $cats = wp_get_post_categories($post_id); … … 236 226 237 227 function wp_create_category($cat_name) { 238 if ( $id = category_exists($cat_name) ) 239 return $id; 240 $cat_array = array('cat_name' => $cat_name, 'type' => TAXONOMY_CATEGORY); 241 242 if ( $id = category_object_exists($cat_name) ) { 243 $category = get_category($id); 244 $cat_array['type'] = $category->type | $cat_array['type']; 245 $cat_array['cat_ID'] = $id; 246 return wp_update_category($cat_array); 247 } else { 248 return wp_insert_category($cat_array); 249 } 228 $cat_array = compact('cat_name'); 229 return wp_insert_category($cat_array); 250 230 } 251 231 … … 266 246 } 267 247 268 function category_ object_exists($cat_name) {248 function category_exists($cat_name) { 269 249 global $wpdb; 270 250 if (!$category_nicename = sanitize_title($cat_name)) … … 272 252 273 253 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'"); 274 }275 276 function category_exists($cat_name) {277 global $wpdb;278 if (!$category_nicename = sanitize_title($cat_name))279 return 0;280 281 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename' AND ( type & " . TAXONOMY_CATEGORY . " != 0 )");282 }283 284 function tag_exists($tag_name) {285 global $wpdb;286 if (! $tag_nicename = sanitize_title($tag_name))287 return 0;288 289 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$tag_nicename' AND ( type & " . TAXONOMY_TAG . " != 0 )");290 }291 292 function wp_create_tag($tag_name) {293 if ( $id = tag_exists($tag_name) )294 return $id;295 $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG);296 297 if ( $id = category_object_exists($tag_name) ) {298 $category = get_category($id);299 $tag_array['type'] = $category->type | $tag_array['type'];300 $tag_array['cat_ID'] = $id;301 $id = wp_update_category($tag_array);302 return $id;303 } else {304 return wp_insert_category($tag_array);305 }306 254 } 307 255
Note: See TracChangeset
for help on using the changeset viewer.