WordPress.org

Make WordPress Core

Ticket #10076: categories.php

File categories.php, 9.1 KB (added by johnkolbert, 5 years ago)

updated categories.php

Line 
1<?php
2/**
3 * Categories Management Panel
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/** Load WordPress Bootstrap */
10require_once('admin.php');
11
12$title = __('Categories');
13
14wp_reset_vars( array('action', 'cat') );
15
16if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
17        $action = 'bulk-delete';
18
19switch($action) {
20
21case 'addcat':
22
23        check_admin_referer('add-category');
24
25        if ( !current_user_can('manage_categories') )
26                wp_die(__('Cheatin&#8217; uh?'));
27
28        if( wp_insert_category($_POST ) ) {
29                wp_redirect('categories.php?message=1#addcat');
30        } else {
31                wp_redirect('categories.php?message=4#addcat');
32        }
33        exit;
34break;
35
36case 'delete':
37        $cat_ID = (int) $_GET['cat_ID'];
38        check_admin_referer('delete-category_' .  $cat_ID);
39
40        if ( !current_user_can('manage_categories') )
41                wp_die(__('Cheatin&#8217; uh?'));
42
43        $cat_name = get_catname($cat_ID);
44
45        // Don't delete the default cats.
46    if ( $cat_ID == get_option('default_category') )
47                wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
48
49        wp_delete_category($cat_ID);
50
51        wp_redirect('categories.php?message=2');
52        exit;
53
54break;
55
56case 'bulk-delete':
57        check_admin_referer('bulk-categories');
58
59        if ( !current_user_can('manage_categories') )
60                wp_die( __('You are not allowed to delete categories.') );
61
62        foreach ( (array) $_GET['delete'] as $cat_ID ) {
63                $cat_name = get_catname($cat_ID);
64
65                // Don't delete the default cats.
66                if ( $cat_ID == get_option('default_category') )
67                        wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
68
69                wp_delete_category($cat_ID);
70        }
71
72        $sendback = wp_get_referer();
73
74        wp_redirect($sendback);
75        exit();
76
77break;
78case 'edit':
79
80        $title = __('Edit Category');
81
82        require_once ('admin-header.php');
83        $cat_ID = (int) $_GET['cat_ID'];
84        $category = get_category_to_edit($cat_ID);
85        include('edit-category-form.php');
86
87break;
88
89case 'editedcat':
90        $cat_ID = (int) $_POST['cat_ID'];
91        check_admin_referer('update-category_' . $cat_ID);
92
93        if ( !current_user_can('manage_categories') )
94                wp_die(__('Cheatin&#8217; uh?'));
95
96        $location = 'categories.php';
97        if ( $referer = wp_get_original_referer() ) {
98                if ( false !== strpos($referer, 'categories.php') )
99                        $location = $referer;
100        }
101
102        if ( wp_update_category($_POST) )
103                $location = add_query_arg('message', 3, $location);
104        else
105                $location = add_query_arg('message', 5, $location);
106
107        wp_redirect($location);
108
109        exit;
110break;
111
112default:
113
114if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
115         wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
116         exit;
117}
118
119wp_enqueue_script('admin-categories');
120if ( current_user_can('manage_categories') )
121        wp_enqueue_script('inline-edit-tax');
122
123require_once ('admin-header.php');
124
125$messages[1] = __('Category added.');
126$messages[2] = __('Category deleted.');
127$messages[3] = __('Category updated.');
128$messages[4] = __('Category not added.');
129$messages[5] = __('Category not updated.');
130?>
131
132<div class="wrap nosubsub">
133<?php screen_icon(); ?>
134<h2><?php echo wp_specialchars( $title );
135if ( isset($_GET['s']) && $_GET['s'] )
136        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', wp_specialchars( stripslashes($_GET['s']) ) ); ?>
137</h2>
138
139<?php
140if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
141<div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
142<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
143endif; ?>
144
145<form class="search-form topmargin" action="" method="get">
146<p class="search-box">
147        <label class="hidden" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
148        <input type="text" class="search-input" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
149        <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
150</p>
151</form>
152<br class="clear" />
153
154<div id="col-container">
155
156<div id="col-right">
157<div class="col-wrap">
158<form id="posts-filter" action="" method="get">
159<div class="tablenav">
160
161<?php
162$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
163if ( empty($pagenum) )
164        $pagenum = 1;
165if( ! isset( $catsperpage ) || $catsperpage < 0 )
166        $catsperpage = 20;
167
168$page_links = paginate_links( array(
169        'base' => add_query_arg( 'pagenum', '%#%' ),
170        'format' => '',
171        'prev_text' => __('&laquo;'),
172        'next_text' => __('&raquo;'),
173        'total' => ceil(wp_count_terms('category') / $catsperpage),
174        'current' => $pagenum
175));
176
177if ( $page_links )
178        echo "<div class='tablenav-pages'>$page_links</div>";
179?>
180
181<div class="alignleft actions">
182<select name="action">
183<option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
184<option value="delete"><?php _e('Delete'); ?></option>
185</select>
186<input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
187<?php wp_nonce_field('bulk-categories'); ?>
188</div>
189
190<br class="clear" />
191</div>
192
193<div class="clear"></div>
194
195<table class="widefat fixed" cellspacing="0">
196        <thead>
197        <tr>
198<?php print_column_headers('categories'); ?>
199        </tr>
200        </thead>
201
202        <tfoot>
203        <tr>
204<?php print_column_headers('categories', false); ?>
205        </tr>
206        </tfoot>
207
208        <tbody id="the-list" class="list:cat">
209<?php
210cat_rows(0, 0, 0, $pagenum, $catsperpage);
211?>
212        </tbody>
213</table>
214
215<div class="tablenav">
216<?php
217if ( $page_links )
218        echo "<div class='tablenav-pages'>$page_links</div>";
219?>
220
221<div class="alignleft actions">
222<select name="action2">
223<option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
224<option value="delete"><?php _e('Delete'); ?></option>
225</select>
226<input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
227<?php wp_nonce_field('bulk-categories'); ?>
228</div>
229
230<br class="clear" />
231</div>
232
233</form>
234
235<div class="form-wrap">
236<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>
237<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>
238</div>
239
240</div>
241</div><!-- /col-right -->
242
243<div id="col-left">
244<div class="col-wrap">
245
246<?php if ( current_user_can('manage_categories') ) { ?>
247<?php $category = (object) array(); $category->parent = 0; do_action('add_category_form_pre', $category); ?>
248
249<div class="form-wrap">
250<h3><?php _e('Add Category'); ?></h3>
251<div id="ajax-response"></div>
252<form name="addcat" id="addcat" method="post" action="categories.php" class="add:the-list: validate">
253<input type="hidden" name="action" value="addcat" />
254<?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-category'); ?>
255
256<div class="form-field form-required">
257        <label for="cat_name"><?php _e('Category Name') ?></label>
258        <input name="cat_name" id="cat_name" type="text" value="" size="40" aria-required="true" />
259    <p><?php _e('The name is used to identify the category almost everywhere, for example under the post or in the category widget.'); ?></p>
260</div>
261
262<div class="form-field">
263        <label for="category_nicename"><?php _e('Category Slug') ?></label>
264        <input name="category_nicename" id="category_nicename" type="text" value="" size="40" />
265    <p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
266</div>
267
268<div class="form-field">
269        <label for="category_parent"><?php _e('Category Parent') ?></label>
270        <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
271    <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
272</div>
273
274<div class="form-field">
275        <label for="category_description"><?php _e('Description') ?></label>
276        <textarea name="category_description" id="category_description" rows="5" cols="40"></textarea>
277    <p><?php _e('The description is not prominent by default, however some themes may show it.'); ?></p>
278</div>
279
280<?php do_action('edit_category_form', $category); ?>
281<p class="submit"><input type="submit" class="button" name="submit" value="<?php _e('Add Category'); ?>" /></p>
282</form></div>
283
284<?php } ?>
285
286</div>
287</div><!-- /col-left -->
288
289</div><!-- /col-container -->
290</div><!-- /wrap -->
291
292<script type="text/javascript">
293/* <![CDATA[ */
294(function($){
295        $(document).ready(function(){
296                $('#doaction, #doaction2').click(function(){
297                        if ( $('select[name^="action"]').val() == 'delete' ) {
298                                var m = '<?php echo js_escape(__("You are about to delete the selected categories.\n  'Cancel' to stop, 'OK' to delete.")); ?>';
299                                return showNotice.warn(m);
300                        }
301                });
302        });
303})(jQuery);
304/* ]]> */
305</script>
306
307<?php
308inline_edit_term_row('categories');
309
310break;
311}
312
313include('admin-footer.php');
314
315?>