Make WordPress Core


Ignore:
Timestamp:
07/03/2005 07:26:51 PM (21 years ago)
Author:
ryan
Message:

wp_insert_category(), wp_update_category(), wp_delete_category().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/categories.php

    r2446 r2695  
    2424
    2525case 'addcat':
     26
    2627        if ($user_level < 3)
    2728                die (__('Cheatin&#8217; uh?'));
    2829       
    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
    3832        header('Location: categories.php?message=1#addcat');
    3933break;
    … …  
    4337        check_admin_referer();
    4438
     39        if ( $user_level < 3 )
     40                die (__('Cheatin&#8217; uh?'));
     41
    4542        $cat_ID = (int) $_GET['cat_ID'];
    4643        $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;
    4944
    5045        if ( 1 == $cat_ID )
    5146                die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name));
    5247
    53         if ( $user_level < 3 )
    54                 die (__('Cheatin&#8217; 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);
    6049
    6150        header('Location: categories.php?message=2');
    … …  
    6756    require_once ('admin-header.php');
    6857    $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);
    7159    ?>
    7260
    … …  
    7765                <tr>
    7866                  <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>
    8169                </tr>
    8270                <tr>
    … …  
    8775                        <th scope="row"><?php _e('Category parent:') ?></th>
    8876                        <td>       
    89                         <select name='cat'>
     77                        <select name='category_parent'>
    9078          <option value='0' <?php if (!$category->category_parent) echo " selected='selected'"; ?>><?php _e('None') ?></option>
    9179          <?php wp_dropdown_cats($category->cat_ID, $category->category_parent); ?>
    … …  
    10997                die (__('Cheatin&#8217; uh?'));
    11098       
    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);
    117100
    118101        header('Location: categories.php?message=3');
    … …  
    166149        <input type="text" name="cat_name" value="" /></p>
    167150        <p><?php _e('Category parent:') ?><br />
    168         <select name='cat' class='postform'>
     151        <select name='category_parent' class='postform'>
    169152        <option value='0'><?php _e('None') ?></option>
    170153        <?php wp_dropdown_cats(0); ?>
Note: See TracChangeset for help on using the changeset viewer.