| 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 |
switch($action) { |
|---|
| 10 |
|
|---|
| 11 |
case 'addcat': |
|---|
| 12 |
|
|---|
| 13 |
check_admin_referer('add-category'); |
|---|
| 14 |
|
|---|
| 15 |
if ( !current_user_can('manage_categories') ) |
|---|
| 16 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 17 |
|
|---|
| 18 |
if( wp_insert_category($_POST ) ) { |
|---|
| 19 |
wp_redirect('categories.php?message=1#addcat'); |
|---|
| 20 |
} else { |
|---|
| 21 |
wp_redirect('categories.php?message=4#addcat'); |
|---|
| 22 |
} |
|---|
| 23 |
exit; |
|---|
| 24 |
break; |
|---|
| 25 |
|
|---|
| 26 |
case 'delete': |
|---|
| 27 |
$cat_ID = (int) $_GET['cat_ID']; |
|---|
| 28 |
check_admin_referer('delete-category_' . $cat_ID); |
|---|
| 29 |
|
|---|
| 30 |
if ( !current_user_can('manage_categories') ) |
|---|
| 31 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 32 |
|
|---|
| 33 |
$cat_name = get_catname($cat_ID); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
if ( $cat_ID == get_option('default_category') ) |
|---|
| 37 |
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name)); |
|---|
| 38 |
|
|---|
| 39 |
if ( $cat_ID == get_option('default_link_category') ) |
|---|
| 40 |
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one for links"), $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 'edit': |
|---|
| 50 |
|
|---|
| 51 |
require_once ('admin-header.php'); |
|---|
| 52 |
$cat_ID = (int) $_GET['cat_ID']; |
|---|
| 53 |
$category = get_category_to_edit($cat_ID); |
|---|
| 54 |
include('edit-category-form.php'); |
|---|
| 55 |
|
|---|
| 56 |
break; |
|---|
| 57 |
|
|---|
| 58 |
case 'editedcat': |
|---|
| 59 |
$cat_ID = (int) $_POST['cat_ID']; |
|---|
| 60 |
check_admin_referer('update-category_' . $cat_ID); |
|---|
| 61 |
|
|---|
| 62 |
if ( !current_user_can('manage_categories') ) |
|---|
| 63 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 64 |
|
|---|
| 65 |
if ( wp_update_category($_POST) ) |
|---|
| 66 |
wp_redirect('categories.php?message=3'); |
|---|
| 67 |
else |
|---|
| 68 |
wp_redirect('categories.php?message=5'); |
|---|
| 69 |
|
|---|
| 70 |
exit; |
|---|
| 71 |
break; |
|---|
| 72 |
|
|---|
| 73 |
default: |
|---|
| 74 |
|
|---|
| 75 |
wp_enqueue_script( 'admin-categories' ); |
|---|
| 76 |
require_once ('admin-header.php'); |
|---|
| 77 |
|
|---|
| 78 |
$messages[1] = __('Category added.'); |
|---|
| 79 |
$messages[2] = __('Category deleted.'); |
|---|
| 80 |
$messages[3] = __('Category updated.'); |
|---|
| 81 |
$messages[4] = __('Category not added.'); |
|---|
| 82 |
$messages[5] = __('Category not updated.'); |
|---|
| 83 |
?> |
|---|
| 84 |
|
|---|
| 85 |
<?php if (isset($_GET['message'])) : ?> |
|---|
| 86 |
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> |
|---|
| 87 |
<?php endif; ?> |
|---|
| 88 |
|
|---|
| 89 |
<div class="wrap"> |
|---|
| 90 |
<?php if ( current_user_can('manage_categories') ) : ?> |
|---|
| 91 |
<h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2> |
|---|
| 92 |
<?php else : ?> |
|---|
| 93 |
<h2><?php _e('Categories') ?> </h2> |
|---|
| 94 |
<?php endif; ?> |
|---|
| 95 |
<table class="widefat"> |
|---|
| 96 |
<thead> |
|---|
| 97 |
<tr> |
|---|
| 98 |
<th scope="col" style="text-align: center"><?php _e('ID') ?></th> |
|---|
| 99 |
<th scope="col"><?php _e('Name') ?></th> |
|---|
| 100 |
<th scope="col"><?php _e('Description') ?></th> |
|---|
| 101 |
<th scope="col" width="90" style="text-align: center"><?php _e('Posts') ?></th> |
|---|
| 102 |
<th colspan="2" style="text-align: center"><?php _e('Action') ?></th> |
|---|
| 103 |
</tr> |
|---|
| 104 |
</thead> |
|---|
| 105 |
<tbody id="the-list"> |
|---|
| 106 |
<?php |
|---|
| 107 |
cat_rows(); |
|---|
| 108 |
?> |
|---|
| 109 |
</tbody> |
|---|
| 110 |
</table> |
|---|
| 111 |
|
|---|
| 112 |
</div> |
|---|
| 113 |
|
|---|
| 114 |
<?php if ( current_user_can('manage_categories') ) : ?> |
|---|
| 115 |
<div class="wrap"> |
|---|
| 116 |
<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> |
|---|
| 117 |
<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> |
|---|
| 118 |
</div> |
|---|
| 119 |
|
|---|
| 120 |
<?php include('edit-category-form.php'); ?> |
|---|
| 121 |
|
|---|
| 122 |
<?php endif; ?> |
|---|
| 123 |
|
|---|
| 124 |
<?php |
|---|
| 125 |
break; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
include('admin-footer.php'); |
|---|
| 129 |
|
|---|
| 130 |
?> |
|---|
| 131 |
|
|---|