| 1 |
<?php |
|---|
| 2 |
require_once('admin.php'); |
|---|
| 3 |
|
|---|
| 4 |
$title = __('Categories'); |
|---|
| 5 |
$parent_file = 'edit.php'; |
|---|
| 6 |
$list_js = true; |
|---|
| 7 |
|
|---|
| 8 |
$wpvarstoreset = array('action','cat'); |
|---|
| 9 |
for ($i=0; $i<count($wpvarstoreset); $i += 1) { |
|---|
| 10 |
$wpvar = $wpvarstoreset[$i]; |
|---|
| 11 |
if (!isset($$wpvar)) { |
|---|
| 12 |
if (empty($_POST["$wpvar"])) { |
|---|
| 13 |
if (empty($_GET["$wpvar"])) { |
|---|
| 14 |
$$wpvar = ''; |
|---|
| 15 |
} else { |
|---|
| 16 |
$$wpvar = $_GET["$wpvar"]; |
|---|
| 17 |
} |
|---|
| 18 |
} else { |
|---|
| 19 |
$$wpvar = $_POST["$wpvar"]; |
|---|
| 20 |
} |
|---|
| 21 |
} |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
switch($action) { |
|---|
| 25 |
|
|---|
| 26 |
case 'addcat': |
|---|
| 27 |
|
|---|
| 28 |
check_admin_referer('add-category'); |
|---|
| 29 |
|
|---|
| 30 |
if ( !current_user_can('manage_categories') ) |
|---|
| 31 |
die (__('Cheatin’ uh?')); |
|---|
| 32 |
|
|---|
| 33 |
wp_insert_category($_POST); |
|---|
| 34 |
|
|---|
| 35 |
wp_redirect('categories.php?message=1#addcat'); |
|---|
| 36 |
exit; |
|---|
| 37 |
break; |
|---|
| 38 |
|
|---|
| 39 |
case 'delete': |
|---|
| 40 |
$cat_ID = (int) $_GET['cat_ID']; |
|---|
| 41 |
check_admin_referer('delete-category_' . $cat_ID); |
|---|
| 42 |
|
|---|
| 43 |
if ( !current_user_can('manage_categories') ) |
|---|
| 44 |
die (__('Cheatin’ uh?')); |
|---|
| 45 |
|
|---|
| 46 |
$cat_name = get_catname($cat_ID); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
if ( $cat_ID == get_option('default_category') ) |
|---|
| 50 |
die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name)); |
|---|
| 51 |
|
|---|
| 52 |
wp_delete_category($cat_ID); |
|---|
| 53 |
|
|---|
| 54 |
wp_redirect('categories.php?message=2'); |
|---|
| 55 |
exit; |
|---|
| 56 |
break; |
|---|
| 57 |
|
|---|
| 58 |
case 'edit': |
|---|
| 59 |
|
|---|
| 60 |
require_once ('admin-header.php'); |
|---|
| 61 |
$cat_ID = (int) $_GET['cat_ID']; |
|---|
| 62 |
$category = get_category_to_edit($cat_ID); |
|---|
| 63 |
?> |
|---|
| 64 |
|
|---|
| 65 |
<div class="wrap"> |
|---|
| 66 |
<h2><?php _e('Edit Category') ?></h2> |
|---|
| 67 |
<form name="editcat" action="categories.php" method="post"> |
|---|
| 68 |
<?php wp_nonce_field('update-category_' . $category->cat_ID); ?> |
|---|
| 69 |
<table class="editform" width="100%" cellspacing="2" cellpadding="5"> |
|---|
| 70 |
<tr> |
|---|
| 71 |
<th width="33%" scope="row"><?php _e('Category name:') ?></th> |
|---|
| 72 |
<td width="67%"><input name="cat_name" type="text" value="<?php echo attribute_escape($category->cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" /> |
|---|
| 73 |
<input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" /></td> |
|---|
| 74 |
</tr> |
|---|
| 75 |
<tr> |
|---|
| 76 |
<th scope="row"><?php _e('Category slug:') ?></th> |
|---|
| 77 |
<td><input name="category_nicename" type="text" value="<?php echo attribute_escape($category->category_nicename); ?>" size="40" /></td> |
|---|
| 78 |
</tr> |
|---|
| 79 |
<tr> |
|---|
| 80 |
<th scope="row"><?php _e('Category parent:') ?></th> |
|---|
| 81 |
<td> |
|---|
| 82 |
<select name='category_parent'> |
|---|
| 83 |
<option value='0' <?php if (!$category->category_parent) echo " selected='selected'"; ?>><?php _e('None') ?></option> |
|---|
| 84 |
<?php wp_dropdown_cats($category->cat_ID, $category->category_parent); ?> |
|---|
| 85 |
</select></td> |
|---|
| 86 |
</tr> |
|---|
| 87 |
<tr> |
|---|
| 88 |
<th scope="row"><?php _e('Description:') ?></th> |
|---|
| 89 |
<td><textarea name="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->category_description); ?></textarea></td> |
|---|
| 90 |
</tr> |
|---|
| 91 |
</table> |
|---|
| 92 |
<p class="submit"><input type="submit" name="submit" value="<?php _e('Edit category') ?> »" /></p> |
|---|
| 93 |
</form> |
|---|
| 94 |
<p><a href="categories.php"><?php _e('« Return to category list'); ?></a></p> |
|---|
| 95 |
</div> |
|---|
| 96 |
<?php |
|---|
| 97 |
|
|---|
| 98 |
break; |
|---|
| 99 |
|
|---|
| 100 |
case 'editedcat': |
|---|
| 101 |
$cat_ID = (int) $_POST['cat_ID']; |
|---|
| 102 |
check_admin_referer('update-category_' . $cat_ID); |
|---|
| 103 |
|
|---|
| 104 |
if ( !current_user_can('manage_categories') ) |
|---|
| 105 |
die (__('Cheatin’ uh?')); |
|---|
| 106 |
|
|---|
| 107 |
wp_update_category($_POST); |
|---|
| 108 |
|
|---|
| 109 |
wp_redirect('categories.php?message=3'); |
|---|
| 110 |
exit; |
|---|
| 111 |
break; |
|---|
| 112 |
|
|---|
| 113 |
default: |
|---|
| 114 |
|
|---|
| 115 |
require_once ('admin-header.php'); |
|---|
| 116 |
|
|---|
| 117 |
$messages[1] = __('Category added.'); |
|---|
| 118 |
$messages[2] = __('Category deleted.'); |
|---|
| 119 |
$messages[3] = __('Category updated.'); |
|---|
| 120 |
?> |
|---|
| 121 |
|
|---|
| 122 |
<?php if (isset($_GET['message'])) : ?> |
|---|
| 123 |
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> |
|---|
| 124 |
<?php endif; ?> |
|---|
| 125 |
|
|---|
| 126 |
<div class="wrap"> |
|---|
| 127 |
<?php if ( current_user_can('manage_categories') ) : ?> |
|---|
| 128 |
<h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2> |
|---|
| 129 |
<?php else : ?> |
|---|
| 130 |
<h2><?php _e('Categories') ?> </h2> |
|---|
| 131 |
<?php endif; ?> |
|---|
| 132 |
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3"> |
|---|
| 133 |
<tr> |
|---|
| 134 |
<th scope="col"><?php _e('ID') ?></th> |
|---|
| 135 |
<th scope="col"><?php _e('Name') ?></th> |
|---|
| 136 |
<th scope="col"><?php _e('Description') ?></th> |
|---|
| 137 |
<th scope="col"><?php _e('# Posts') ?></th> |
|---|
| 138 |
<th colspan="2"><?php _e('Action') ?></th> |
|---|
| 139 |
</tr> |
|---|
| 140 |
<?php |
|---|
| 141 |
cat_rows(); |
|---|
| 142 |
?> |
|---|
| 143 |
</table> |
|---|
| 144 |
|
|---|
| 145 |
<div id="ajax-response"></div> |
|---|
| 146 |
|
|---|
| 147 |
</div> |
|---|
| 148 |
|
|---|
| 149 |
<?php if ( current_user_can('manage_categories') ) : ?> |
|---|
| 150 |
<div class="wrap"> |
|---|
| 151 |
<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete posts from that category, it will just set them back to the default category <strong>%s</strong>.'), get_catname(get_option('default_category'))) ?></p> |
|---|
| 152 |
</div> |
|---|
| 153 |
|
|---|
| 154 |
<div class="wrap"> |
|---|
| 155 |
<h2><?php _e('Add New Category') ?></h2> |
|---|
| 156 |
<form name="addcat" id="addcat" action="categories.php" method="post"> |
|---|
| 157 |
<?php wp_nonce_field('add-category'); ?> |
|---|
| 158 |
<p><?php _e('Name:') ?><br /> |
|---|
| 159 |
<input type="text" name="cat_name" value="" /></p> |
|---|
| 160 |
<p><?php _e('Category parent:') ?><br /> |
|---|
| 161 |
<select name='category_parent' class='postform'> |
|---|
| 162 |
<option value='0'><?php _e('None') ?></option> |
|---|
| 163 |
<?php wp_dropdown_cats(0); ?> |
|---|
| 164 |
</select></p> |
|---|
| 165 |
<p><?php _e('Description: (optional)') ?> <br /> |
|---|
| 166 |
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p> |
|---|
| 167 |
<p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category »') ?>" /></p> |
|---|
| 168 |
</form> |
|---|
| 169 |
</div> |
|---|
| 170 |
<?php endif; ?> |
|---|
| 171 |
|
|---|
| 172 |
<?php |
|---|
| 173 |
break; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
include('admin-footer.php'); |
|---|
| 177 |
?> |
|---|
| 178 |
|
|---|