Changeset 2695
- Timestamp:
- 07/03/2005 07:26:51 PM (19 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r2662 r2695 203 203 204 204 return $comment; 205 } 206 207 function get_category_to_edit($id) { 208 $category = get_category($id); 209 210 return $category; 211 } 212 213 function wp_insert_category($catarr) { 214 global $wpdb; 215 216 extract($catarr); 217 218 $cat_ID = (int) $cat_ID; 219 220 // Are we updating or creating? 221 if ( !empty($cat_ID) ) { 222 $update = true; 223 } else { 224 $update = false; 225 $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->categories'"); 226 $cat_ID = $id_result->Auto_increment; 227 } 228 229 $cat_name = wp_specialchars($cat_name); 230 231 if ( empty($category_nicename) ) 232 $category_nicename = sanitize_title($cat_name, $cat_ID); 233 else 234 $category_nicename = sanitize_title($category_nicename, $cat_ID); 235 236 if ( empty($category_description) ) 237 $category_description = ''; 238 239 if ( empty($category_parent) ) 240 $category_parent = 0; 241 242 if ( !$update) 243 $query = "INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')"; 244 else 245 $query = "UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'"; 246 247 $result = $wpdb->query($query); 248 249 if ( $update ) { 250 $rval = $wpdb->rows_affected; 251 do_action('edit_category', $cat_ID); 252 } else { 253 $rval = $wpdb->insert_id; 254 do_action('create_category', $cat_ID); 255 } 256 257 return $rval; 258 } 259 260 function wp_update_category($catarr) { 261 global $wpdb; 262 263 $cat_ID = (int) $catarr['cat_ID']; 264 265 // First, get all of the original fields 266 $category = get_category($cat_ID, ARRAY_A); 267 268 // Escape data pulled from DB. 269 $category = add_magic_quotes($category); 270 271 // Merge old and new fields with new fields overwriting old ones. 272 $catarr = array_merge($category, $catarr); 273 274 return wp_insert_category($catarr); 275 } 276 277 function wp_delete_category($cat_ID) { 278 global $wpdb; 279 280 $cat_ID = (int) $cat_ID; 281 282 // Don't delete the default cat. 283 if ( 1 == $cat_ID ) 284 return 0; 285 286 $category = get_category($cat_ID); 287 288 $parent = $category->category_parent; 289 290 // Delete the category. 291 $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 292 293 // Update children to point to new parent. 294 $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 295 296 // TODO: Only set categories to general if they're not in another category already 297 $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'"); 298 299 do_action('delete_category', $cat_ID); 300 301 return 1; 205 302 } 206 303 -
trunk/wp-admin/categories.php
r2446 r2695 24 24 25 25 case 'addcat': 26 26 27 if ($user_level < 3) 27 28 die (__('Cheatin’ uh?')); 28 29 29 $cat_name= wp_specialchars($_POST['cat_name']); 30 $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->categories'"); 31 $cat_ID = $id_result->Auto_increment; 32 $category_nicename = sanitize_title($cat_name, $cat_ID); 33 $category_description = $_POST['category_description']; 34 $cat = intval($_POST['cat']); 35 36 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')"); 37 30 wp_insert_category($_POST); 31 38 32 header('Location: categories.php?message=1#addcat'); 39 33 break; … … 43 37 check_admin_referer(); 44 38 39 if ( $user_level < 3 ) 40 die (__('Cheatin’ uh?')); 41 45 42 $cat_ID = (int) $_GET['cat_ID']; 46 43 $cat_name = get_catname($cat_ID); 47 $category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");48 $cat_parent = $category->category_parent;49 44 50 45 if ( 1 == $cat_ID ) 51 46 die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name)); 52 47 53 if ( $user_level < 3 ) 54 die (__('Cheatin’ uh?')); 55 56 $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 57 $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$cat_parent' WHERE category_parent = '$cat_ID'"); 58 // TODO: Only set categories to general if they're not in another category already 59 $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'"); 48 wp_delete_category($cat_ID); 60 49 61 50 header('Location: categories.php?message=2'); … … 67 56 require_once ('admin-header.php'); 68 57 $cat_ID = (int) $_GET['cat_ID']; 69 $category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 70 $cat_name = $category->cat_name; 58 $category = get_category_to_edit($cat_ID); 71 59 ?> 72 60 … … 77 65 <tr> 78 66 <th width="33%" scope="row"><?php _e('Category name:') ?></th> 79 <td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($cat _name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" />80 <input type="hidden" name="cat_ID" value="<?php echo $cat _ID ?>" /></td>67 <td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($category->cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" /> 68 <input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" /></td> 81 69 </tr> 82 70 <tr> … … 87 75 <th scope="row"><?php _e('Category parent:') ?></th> 88 76 <td> 89 <select name='cat '>77 <select name='category_parent'> 90 78 <option value='0' <?php if (!$category->category_parent) echo " selected='selected'"; ?>><?php _e('None') ?></option> 91 79 <?php wp_dropdown_cats($category->cat_ID, $category->category_parent); ?> … … 109 97 die (__('Cheatin’ uh?')); 110 98 111 $cat_name = wp_specialchars($_POST['cat_name']); 112 $cat_ID = (int) $_POST['cat_ID']; 113 $category_nicename = sanitize_title($_POST['category_nicename'], $cat_ID); 114 $category_description = $_POST['category_description']; 115 116 $wpdb->query("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$cat' WHERE cat_ID = '$cat_ID'"); 99 wp_update_category($_POST); 117 100 118 101 header('Location: categories.php?message=3'); … … 166 149 <input type="text" name="cat_name" value="" /></p> 167 150 <p><?php _e('Category parent:') ?><br /> 168 <select name='cat ' class='postform'>151 <select name='category_parent' class='postform'> 169 152 <option value='0'><?php _e('None') ?></option> 170 153 <?php wp_dropdown_cats(0); ?>
Note: See TracChangeset
for help on using the changeset viewer.