mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
wp_insert_category(), wp_update_category(), wp_delete_category().
git-svn-id: https://develop.svn.wordpress.org/trunk@2695 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+13
-30
@@ -23,18 +23,12 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
||||
switch($action) {
|
||||
|
||||
case 'addcat':
|
||||
|
||||
if ($user_level < 3)
|
||||
die (__('Cheatin’ uh?'));
|
||||
|
||||
$cat_name= wp_specialchars($_POST['cat_name']);
|
||||
$id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->categories'");
|
||||
$cat_ID = $id_result->Auto_increment;
|
||||
$category_nicename = sanitize_title($cat_name, $cat_ID);
|
||||
$category_description = $_POST['category_description'];
|
||||
$cat = intval($_POST['cat']);
|
||||
|
||||
$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')");
|
||||
|
||||
wp_insert_category($_POST);
|
||||
|
||||
header('Location: categories.php?message=1#addcat');
|
||||
break;
|
||||
|
||||
@@ -42,21 +36,16 @@ case 'delete':
|
||||
|
||||
check_admin_referer();
|
||||
|
||||
if ( $user_level < 3 )
|
||||
die (__('Cheatin’ uh?'));
|
||||
|
||||
$cat_ID = (int) $_GET['cat_ID'];
|
||||
$cat_name = get_catname($cat_ID);
|
||||
$category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
|
||||
$cat_parent = $category->category_parent;
|
||||
|
||||
if ( 1 == $cat_ID )
|
||||
die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name));
|
||||
|
||||
if ( $user_level < 3 )
|
||||
die (__('Cheatin’ uh?'));
|
||||
|
||||
$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
|
||||
$wpdb->query("UPDATE $wpdb->categories SET category_parent = '$cat_parent' WHERE category_parent = '$cat_ID'");
|
||||
// TODO: Only set categories to general if they're not in another category already
|
||||
$wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'");
|
||||
wp_delete_category($cat_ID);
|
||||
|
||||
header('Location: categories.php?message=2');
|
||||
|
||||
@@ -66,8 +55,7 @@ case 'edit':
|
||||
|
||||
require_once ('admin-header.php');
|
||||
$cat_ID = (int) $_GET['cat_ID'];
|
||||
$category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
|
||||
$cat_name = $category->cat_name;
|
||||
$category = get_category_to_edit($cat_ID);
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
@@ -76,8 +64,8 @@ case 'edit':
|
||||
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
|
||||
<tr>
|
||||
<th width="33%" scope="row"><?php _e('Category name:') ?></th>
|
||||
<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" />
|
||||
<input type="hidden" name="cat_ID" value="<?php echo $cat_ID ?>" /></td>
|
||||
<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" />
|
||||
<input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Category slug:') ?></th>
|
||||
@@ -86,7 +74,7 @@ case 'edit':
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Category parent:') ?></th>
|
||||
<td>
|
||||
<select name='cat'>
|
||||
<select name='category_parent'>
|
||||
<option value='0' <?php if (!$category->category_parent) echo " selected='selected'"; ?>><?php _e('None') ?></option>
|
||||
<?php wp_dropdown_cats($category->cat_ID, $category->category_parent); ?>
|
||||
</select></td>
|
||||
@@ -108,12 +96,7 @@ case 'editedcat':
|
||||
if ($user_level < 3)
|
||||
die (__('Cheatin’ uh?'));
|
||||
|
||||
$cat_name = wp_specialchars($_POST['cat_name']);
|
||||
$cat_ID = (int) $_POST['cat_ID'];
|
||||
$category_nicename = sanitize_title($_POST['category_nicename'], $cat_ID);
|
||||
$category_description = $_POST['category_description'];
|
||||
|
||||
$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'");
|
||||
wp_update_category($_POST);
|
||||
|
||||
header('Location: categories.php?message=3');
|
||||
break;
|
||||
@@ -165,7 +148,7 @@ cat_rows();
|
||||
<p><?php _e('Name:') ?><br />
|
||||
<input type="text" name="cat_name" value="" /></p>
|
||||
<p><?php _e('Category parent:') ?><br />
|
||||
<select name='cat' class='postform'>
|
||||
<select name='category_parent' class='postform'>
|
||||
<option value='0'><?php _e('None') ?></option>
|
||||
<?php wp_dropdown_cats(0); ?>
|
||||
</select></p>
|
||||
|
||||
Reference in New Issue
Block a user