root/trunk/wp-admin/categories.php

Revision 1530, 8.6 kB (checked in by donncha, 1 hour ago)

WP Merge with revision 9808

  • Property svn:eol-style set to native
Line 
1 <?php
2 /**
3  * Categories Management Panel
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** Load WordPress Bootstrap */
10 require_once('admin.php');
11
12 $title = __('Categories');
13
14 wp_reset_vars( array('action', 'cat') );
15
16 if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
17     $action = 'bulk-delete';
18
19 switch($action) {
20
21 case '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;
34 break;
35
36 case '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
54 break;
55
56 case '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
77 break;
78 case '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
87 break;
88
89 case '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;
110 break;
111
112 default:
113
114 if ( 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
119 wp_enqueue_script('admin-categories');
120 if ( current_user_can('manage_categories') )
121     wp_enqueue_script('inline-edit-tax');
122
123 require_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 <h2><?php echo wp_specialchars( $title ); ?></h2>
134
135 <?php
136 if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
137 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
138 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
139 endif; ?>
140
141 <form class="search-form topmargin" action="" method="get">
142 <p class="search-box">
143     <label class="hidden" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
144     <input type="text" class="search-input" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
145     <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
146 </p>
147 </form>
148 <br class="clear" />
149
150 <div id="col-container">
151
152 <div id="col-right">
153 <div class="col-wrap">
154 <form id="posts-filter" action="" method="get">
155 <div class="tablenav">
156
157 <?php
158 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
159 if ( empty($pagenum) )
160     $pagenum = 1;
161 if( ! isset( $catsperpage ) || $catsperpage < 0 )
162     $catsperpage = 20;
163
164 $page_links = paginate_links( array(
165     'base' => add_query_arg( 'pagenum', '%#%' ),
166     'format' => '',
167     'prev_text' => __('&larr;'),
168     'next_text' => __('&rarr;'),
169     'total' => ceil(wp_count_terms('category') / $catsperpage),
170     'current' => $pagenum
171 ));
172
173 if ( $page_links )
174     echo "<div class='tablenav-pages'>$page_links</div>";
175 ?>
176
177 <div class="alignleft actions">
178 <select name="action">
179 <option value="" selected="selected"><?php _e('Actions'); ?></option>
180 <option value="delete"><?php _e('Delete'); ?></option>
181 </select>
182 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
183 <?php wp_nonce_field('bulk-categories'); ?>
184 </div>
185
186 <br class="clear" />
187 </div>
188
189 <div class="clear"></div>
190
191 <table class="widefat fixed" cellspacing="0">
192     <thead>
193     <tr>
194 <?php print_column_headers('categories'); ?>
195     </tr>
196     </thead>
197
198     <tfoot>
199     <tr>
200 <?php print_column_headers('categories', false); ?>
201     </tr>
202     </tfoot>
203
204     <tbody id="the-list" class="list:cat">
205 <?php
206 cat_rows(0, 0, 0, $pagenum, $catsperpage);
207 ?>
208     </tbody>
209 </table>
210
211 <div class="tablenav">
212 <?php
213 if ( $page_links )
214     echo "<div class='tablenav-pages'>$page_links</div>";
215 ?>
216
217 <div class="alignleft actions">
218 <select name="action2">
219 <option value="" selected="selected"><?php _e('Actions'); ?></option>
220 <option value="delete"><?php _e('Delete'); ?></option>
221 </select>
222 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
223 <?php wp_nonce_field('bulk-categories'); ?>
224 </div>
225
226 <br class="clear" />
227 </div>
228
229 </form>
230
231 <div class="form-wrap">
232 <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>
233 <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>
234 </div>
235
236 </div>
237 </div><!-- /col-right -->
238
239 <div id="col-left">
240 <div class="col-wrap">
241
242 <?php if ( current_user_can('manage_categories') ) { ?>
243 <?php $category = (object) array(); $category->parent = 0; do_action('add_category_form_pre', $category); ?>
244
245 <div class="form-wrap">
246 <h3><?php _e('Add Category'); ?></h3>
247 <div id="ajax-response"></div>
248 <form name="addcat" id="addcat" method="post" action="categories.php" class="add:the-list: validate">
249 <input type="hidden" name="action" value="addcat" />
250 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-category'); ?>
251
252 <div class="form-field form-required">
253     <label for="cat_name"><?php _e('Category Name') ?></label>
254     <input name="cat_name" id="cat_name" type="text" value="" size="40" aria-required="true" />
255     <p><?php _e('The name is used to identify the category almost everywhere, for example under the post or in the category widget.'); ?></p>
256 </div>
257
258 <div class="form-field">
259     <label for="category_parent"><?php _e('Category Parent') ?></label>
260     <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
261     <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>
262 </div>
263
264 <div class="form-field">
265     <label for="category_description"><?php _e('Description') ?></label>
266     <textarea name="category_description" id="category_description" rows="5" cols="40"></textarea>
267     <p><?php _e('The description is not prominent by default, however some themes may show it.'); ?></p>
268 </div>
269
270 <p class="submit"><input type="submit" class="button" name="submit" value="<?php _e('Add Category'); ?>" /></p>
271 <?php do_action('edit_category_form', $category); ?>
272 </form></div>
273
274 <?php } ?>
275
276 </div>
277 </div><!-- /col-left -->
278
279 </div><!-- /col-container -->
280 </div><!-- /wrap -->
281
282 <script type="text/javascript">
283 /* <![CDATA[ */
284 (function($){
285     $(document).ready(function(){
286         $('#doaction, #doaction2').click(function(){
287             if ( $('select[name^="action"]').val() == 'delete' ) {
288                 var m = '<?php echo js_escape(__("You are about to delete the selected categories.\n  'Cancel' to stop, 'OK' to delete.")); ?>';
289                 return showNotice.warn(m);
290             }
291         });
292     });
293 })(jQuery);
294 /* ]]> */
295 </script>
296
297 <?php
298 inline_edit_term_row('category');
299
300 break;
301 }
302
303 include('admin-footer.php');
304
305 ?>
306
Note: See TracBrowser for help on using the browser.