WordPress.org

Make WordPress Core

Ticket #4163: categories.php

File categories.php, 4.0 KB (added by momo360modena, 8 years ago)
Line 
1<?php
2require_once('admin.php');
3
4$title = __('Categories');
5$parent_file = 'edit.php';
6
7wp_reset_vars(array('action', 'cat'));
8
9switch($action) {
10
11case 'addcat':
12
13        check_admin_referer('add-category');
14
15        if ( !current_user_can('manage_categories') )
16                wp_die(__('Cheatin&#8217; 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;
24break;
25
26case '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&#8217; uh?'));
32
33        $cat_name = get_catname($cat_ID);
34
35        // Don't delete the default cats.
36    if ( $cat_ID == get_option('default_category') )
37                wp_die(sprintf(__("Can&#8217;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&#8217;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
47break;
48
49case '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
56break;
57
58case '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&#8217; 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;
71break;
72
73default:
74
75wp_enqueue_script( 'admin-categories' );
76require_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 scope="col" width="90" style="text-align: center"><?php _e('Links') ?></th>
103        <th colspan="2" style="text-align: center"><?php _e('Action') ?></th>
104        </tr>
105        </thead>
106        <tbody id="the-list">
107<?php
108cat_rows();
109?>
110        </tbody>
111</table>
112
113</div>
114
115<?php if ( current_user_can('manage_categories') ) : ?>
116<div class="wrap">
117<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts and links in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong> and links that were only assigned to the deleted category are set to <strong>%s</strong>.'), apply_filters('the_category', get_catname(get_option('default_category'))), apply_filters('the_category', get_catname(get_option('default_link_category')))) ?></p>
118</div>
119
120<?php include('edit-category-form.php'); ?>
121
122<?php
123$disabled_tag = apply_filters('tags_form_advanced', $disabled_tag);
124if ( $disabled_tag != 1 ) :
125?>
126<div class="wrap">
127<h3><?php _e('Importers &amp; Converters'); ?></h3>
128
129<ul>
130        <li><a href="admin.php?import=wp-cat2tag"><?php _e('Selectively convert categories to tags'); ?></a></li>
131        <li><a href="admin.php?import=utw"><?php _e('Import Ultimate Tag Warrior tags'); ?></a></li>
132</ul>
133</div>
134<?php endif; ?>
135<?php endif; ?>
136
137<?php
138break;
139}
140
141include('admin-footer.php');
142
143?>