| 1 |
<?php |
|---|
| 2 |
require_once('admin.php'); |
|---|
| 3 |
|
|---|
| 4 |
$title = __('Categories'); |
|---|
| 5 |
$parent_file = 'edit.php'; |
|---|
| 6 |
|
|---|
| 7 |
wp_reset_vars(array('action', 'cat')); |
|---|
| 8 |
|
|---|
| 9 |
if ( isset($_GET['deleteit']) && isset($_GET['delete']) ) |
|---|
| 10 |
$action = 'bulk-delete'; |
|---|
| 11 |
|
|---|
| 12 |
switch($action) { |
|---|
| 13 |
|
|---|
| 14 |
case 'addcat': |
|---|
| 15 |
|
|---|
| 16 |
check_admin_referer('add-category'); |
|---|
| 17 |
|
|---|
| 18 |
if ( !current_user_can('manage_categories') ) |
|---|
| 19 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 20 |
|
|---|
| 21 |
if( wp_insert_category($_POST ) ) { |
|---|
| 22 |
wp_redirect('categories.php?message=1#addcat'); |
|---|
| 23 |
} else { |
|---|
| 24 |
wp_redirect('categories.php?message=4#addcat'); |
|---|
| 25 |
} |
|---|
| 26 |
exit; |
|---|
| 27 |
break; |
|---|
| 28 |
|
|---|
| 29 |
case 'delete': |
|---|
| 30 |
$cat_ID = (int) $_GET['cat_ID']; |
|---|
| 31 |
check_admin_referer('delete-category_' . $cat_ID); |
|---|
| 32 |
|
|---|
| 33 |
if ( !current_user_can('manage_categories') ) |
|---|
| 34 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 35 |
|
|---|
| 36 |
$cat_name = get_catname($cat_ID); |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
if ( $cat_ID == get_option('default_category') ) |
|---|
| 40 |
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name)); |
|---|
| 41 |
|
|---|
| 42 |
wp_delete_category($cat_ID); |
|---|
| 43 |
|
|---|
| 44 |
wp_redirect('categories.php?message=2'); |
|---|
| 45 |
exit; |
|---|
| 46 |
|
|---|
| 47 |
break; |
|---|
| 48 |
|
|---|
| 49 |
case 'bulk-delete': |
|---|
| 50 |
check_admin_referer('bulk-categories'); |
|---|
| 51 |
|
|---|
| 52 |
if ( !current_user_can('manage_categories') ) |
|---|
| 53 |
wp_die( __('You are not allowed to delete categories.') ); |
|---|
| 54 |
|
|---|
| 55 |
foreach ( (array) $_GET['delete'] as $cat_ID ) { |
|---|
| 56 |
$cat_name = get_catname($cat_ID); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
if ( $cat_ID == get_option('default_category') ) |
|---|
| 60 |
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name)); |
|---|
| 61 |
|
|---|
| 62 |
wp_delete_category($cat_ID); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
$sendback = wp_get_referer(); |
|---|
| 66 |
$sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); |
|---|
| 67 |
|
|---|
| 68 |
wp_redirect($sendback); |
|---|
| 69 |
exit(); |
|---|
| 70 |
|
|---|
| 71 |
break; |
|---|
| 72 |
case 'edit': |
|---|
| 73 |
|
|---|
| 74 |
require_once ('admin-header.php'); |
|---|
| 75 |
$cat_ID = (int) $_GET['cat_ID']; |
|---|
| 76 |
$category = get_category_to_edit($cat_ID); |
|---|
| 77 |
include('edit-category-form.php'); |
|---|
| 78 |
|
|---|
| 79 |
break; |
|---|
| 80 |
|
|---|
| 81 |
case 'editedcat': |
|---|
| 82 |
$cat_ID = (int) $_POST['cat_ID']; |
|---|
| 83 |
check_admin_referer('update-category_' . $cat_ID); |
|---|
| 84 |
|
|---|
| 85 |
if ( !current_user_can('manage_categories') ) |
|---|
| 86 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 87 |
|
|---|
| 88 |
if ( wp_update_category($_POST) ) |
|---|
| 89 |
wp_redirect('categories.php?message=3'); |
|---|
| 90 |
else |
|---|
| 91 |
wp_redirect('categories.php?message=5'); |
|---|
| 92 |
|
|---|
| 93 |
exit; |
|---|
| 94 |
break; |
|---|
| 95 |
|
|---|
| 96 |
default: |
|---|
| 97 |
|
|---|
| 98 |
if ( !empty($_GET['_wp_http_referer']) ) { |
|---|
| 99 |
wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']))); |
|---|
| 100 |
exit; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
wp_enqueue_script( 'admin-categories' ); |
|---|
| 104 |
wp_enqueue_script('admin-forms'); |
|---|
| 105 |
|
|---|
| 106 |
require_once ('admin-header.php'); |
|---|
| 107 |
|
|---|
| 108 |
$messages[1] = __('Category added.'); |
|---|
| 109 |
$messages[2] = __('Category deleted.'); |
|---|
| 110 |
$messages[3] = __('Category updated.'); |
|---|
| 111 |
$messages[4] = __('Category not added.'); |
|---|
| 112 |
$messages[5] = __('Category not updated.'); |
|---|
| 113 |
?> |
|---|
| 114 |
|
|---|
| 115 |
<?php if (isset($_GET['message'])) : ?> |
|---|
| 116 |
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> |
|---|
| 117 |
<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); |
|---|
| 118 |
endif; ?> |
|---|
| 119 |
|
|---|
| 120 |
<div class="wrap"> |
|---|
| 121 |
<form id="posts-filter" action="" method="get"> |
|---|
| 122 |
<?php if ( current_user_can('manage_categories') ) : ?> |
|---|
| 123 |
<h2><?php printf(__('Manage Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2> |
|---|
| 124 |
<?php else : ?> |
|---|
| 125 |
<h2><?php _e('Manage Categories') ?> </h2> |
|---|
| 126 |
<?php endif; ?> |
|---|
| 127 |
|
|---|
| 128 |
<p id="post-search"> |
|---|
| 129 |
<input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" /> |
|---|
| 130 |
<input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" /> |
|---|
| 131 |
</p> |
|---|
| 132 |
|
|---|
| 133 |
<br class="clear" /> |
|---|
| 134 |
|
|---|
| 135 |
<div class="tablenav"> |
|---|
| 136 |
|
|---|
| 137 |
<div class="alignleft"> |
|---|
| 138 |
<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" /> |
|---|
| 139 |
<?php wp_nonce_field('bulk-categories'); ?> |
|---|
| 140 |
</div> |
|---|
| 141 |
|
|---|
| 142 |
<br class="clear" /> |
|---|
| 143 |
</div> |
|---|
| 144 |
|
|---|
| 145 |
<br class="clear" /> |
|---|
| 146 |
|
|---|
| 147 |
<table class="widefat"> |
|---|
| 148 |
<thead> |
|---|
| 149 |
<tr> |
|---|
| 150 |
<th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('posts-filter'));" /></th> |
|---|
| 151 |
<th scope="col"><?php _e('Name') ?></th> |
|---|
| 152 |
<th scope="col"><?php _e('Description') ?></th> |
|---|
| 153 |
<th scope="col" class="num"><?php _e('Posts') ?></th> |
|---|
| 154 |
</tr> |
|---|
| 155 |
</thead> |
|---|
| 156 |
<tbody id="the-list" class="list:cat"> |
|---|
| 157 |
<?php |
|---|
| 158 |
cat_rows(); |
|---|
| 159 |
?> |
|---|
| 160 |
</tbody> |
|---|
| 161 |
</table> |
|---|
| 162 |
</form> |
|---|
| 163 |
|
|---|
| 164 |
<div class="tablenav"> |
|---|
| 165 |
<br class="clear" /> |
|---|
| 166 |
</div> |
|---|
| 167 |
<br class="clear" /> |
|---|
| 168 |
|
|---|
| 169 |
</div> |
|---|
| 170 |
|
|---|
| 171 |
<?php if ( current_user_can('manage_categories') ) : ?> |
|---|
| 172 |
<div class="wrap"> |
|---|
| 173 |
<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_catname(get_option('default_category')))) ?></p> |
|---|
| 174 |
<p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'admin.php?import=wp-cat2tag') ?></p> |
|---|
| 175 |
</div> |
|---|
| 176 |
|
|---|
| 177 |
<?php include('edit-category-form.php'); ?> |
|---|
| 178 |
|
|---|
| 179 |
<?php endif; ?> |
|---|
| 180 |
|
|---|
| 181 |
<?php |
|---|
| 182 |
break; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
include('admin-footer.php'); |
|---|
| 186 |
|
|---|
| 187 |
?> |
|---|
| 188 |
|
|---|