]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-tags.php
Wordpress 3.0
[autoinstalls/wordpress.git] / wp-admin / edit-tags.php
1 <?php
2 /**
3  * Edit Tags Administration Panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
11
12 wp_reset_vars( array('action', 'tag', 'taxonomy', 'post_type') );
13
14 if ( empty($taxonomy) )
15         $taxonomy = 'post_tag';
16
17 if ( !taxonomy_exists($taxonomy) )
18         wp_die(__('Invalid taxonomy'));
19
20 $tax = get_taxonomy($taxonomy);
21
22 $title = $tax->labels->name;
23
24 if ( empty($post_type) || !in_array( $post_type, get_post_types( array('public' => true) ) ) )
25         $post_type = 'post';
26
27 if ( 'post' != $post_type ) {
28         $parent_file = "edit.php?post_type=$post_type";
29         $submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type";
30 } else {
31         $parent_file = 'edit.php';
32         $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
33 }
34
35 if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
36         $action = 'bulk-delete';
37
38 switch($action) {
39
40 case 'add-tag':
41
42         check_admin_referer('add-tag');
43
44         if ( !current_user_can($tax->cap->edit_terms) )
45                 wp_die(__('Cheatin&#8217; uh?'));
46
47         $ret = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST);
48         $location = 'edit-tags.php?taxonomy=' . $taxonomy;
49         if ( 'post' != $post_type )
50                 $location .= '&post_type=' . $post_type;
51
52         if ( $referer = wp_get_original_referer() ) {
53                 if ( false !== strpos($referer, 'edit-tags.php') )
54                         $location = $referer;
55         }
56
57         if ( $ret && !is_wp_error( $ret ) )
58                 $location = add_query_arg('message', 1, $location);
59         else
60                 $location = add_query_arg('message', 4, $location);
61         wp_redirect($location);
62         exit;
63 break;
64
65 case 'delete':
66         $location = 'edit-tags.php?taxonomy=' . $taxonomy;
67         if ( 'post' != $post_type )
68                 $location .= '&post_type=' . $post_type;
69         if ( $referer = wp_get_referer() ) {
70                 if ( false !== strpos($referer, 'edit-tags.php') )
71                         $location = $referer;
72         }
73
74         if ( !isset( $_GET['tag_ID'] ) ) {
75                 wp_redirect($location);
76                 exit;
77         }
78
79         $tag_ID = (int) $_GET['tag_ID'];
80         check_admin_referer('delete-tag_' .  $tag_ID);
81
82         if ( !current_user_can($tax->cap->delete_terms) )
83                 wp_die(__('Cheatin&#8217; uh?'));
84
85         wp_delete_term( $tag_ID, $taxonomy);
86
87         $location = add_query_arg('message', 2, $location);
88         wp_redirect($location);
89         exit;
90
91 break;
92
93 case 'bulk-delete':
94         check_admin_referer('bulk-tags');
95
96         if ( !current_user_can($tax->cap->delete_terms) )
97                 wp_die(__('Cheatin&#8217; uh?'));
98
99         $tags = (array) $_GET['delete_tags'];
100         foreach( $tags as $tag_ID ) {
101                 wp_delete_term( $tag_ID, $taxonomy);
102         }
103
104         $location = 'edit-tags.php?taxonomy=' . $taxonomy;
105         if ( 'post' != $post_type )
106                 $location .= '&post_type=' . $post_type;
107         if ( $referer = wp_get_referer() ) {
108                 if ( false !== strpos($referer, 'edit-tags.php') )
109                         $location = $referer;
110         }
111
112         $location = add_query_arg('message', 6, $location);
113         wp_redirect($location);
114         exit;
115
116 break;
117
118 case 'edit':
119         $title = $tax->labels->edit_item;
120
121         require_once ('admin-header.php');
122         $tag_ID = (int) $_GET['tag_ID'];
123
124         $tag = get_term($tag_ID, $taxonomy, OBJECT, 'edit');
125         include('./edit-tag-form.php');
126
127 break;
128
129 case 'editedtag':
130         $tag_ID = (int) $_POST['tag_ID'];
131         check_admin_referer('update-tag_' . $tag_ID);
132
133         if ( !current_user_can($tax->cap->edit_terms) )
134                 wp_die(__('Cheatin&#8217; uh?'));
135
136         $ret = wp_update_term($tag_ID, $taxonomy, $_POST);
137
138         $location = 'edit-tags.php?taxonomy=' . $taxonomy;
139         if ( 'post' != $post_type )
140                 $location .= '&post_type=' . $post_type;
141
142         if ( $referer = wp_get_original_referer() ) {
143                 if ( false !== strpos($referer, 'edit-tags.php') )
144                         $location = $referer;
145         }
146
147         if ( $ret && !is_wp_error( $ret ) )
148                 $location = add_query_arg('message', 3, $location);
149         else
150                 $location = add_query_arg('message', 5, $location);
151
152         wp_redirect($location);
153         exit;
154 break;
155
156 default:
157
158 if ( ! empty($_GET['_wp_http_referer']) ) {
159          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
160          exit;
161 }
162
163 wp_enqueue_script('admin-tags');
164 if ( current_user_can($tax->cap->edit_terms) )
165         wp_enqueue_script('inline-edit-tax');
166
167 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) {
168         if ( 'category' == $taxonomy )
169                 $help = '<p>' . sprintf(__('You can use categories to define sections of your site and group related posts. The default category is &#8220;Uncategorized&#8221; until you change it in your <a href="%s">writing settings</a>.'), 'options-writing.php') . '</p>';
170         else
171                 $help = '<p>' . __('You can assign keywords to your posts using Post Tags. Unlike categories, tags have no hierarchy, meaning there&#8217;s no relationship from one tag to another.') . '</p>';
172
173         $help .='<p>' . __('What&#8217;s the difference between categories and tags? Normally, tags are ad-hoc keywords that identify important information in your post (names, subjects, etc) that may or may not recur in other posts, while categories are pre-determined sections. If you think of your site like a book, the categories are like the Table of Contents and the tags are like the terms in the index.') . '</p>';
174
175         if ( 'category' == $taxonomy )
176                 $help .= '<p>' . __('When adding a new category on this screen, you&#8217;ll fill in the following fields:') . '</p>';
177         else
178                 $help .= '<p>' . __('When adding a new tag on this screen, you&#8217;ll fill in the following fields:') . '</p>';
179
180         $help .= '<ul>' .
181                 '<li>' . __('<strong>Name</strong> - The name is how it appears on your site.') . '</li>';
182         if ( ! global_terms_enabled() )
183                 $help .= '<li>' . __('<strong>Slug</strong> - The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.') . '</li>';
184
185         if ( 'category' == $taxonomy )
186                 $help .= '<li>' . __('<strong>Parent</strong> - 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. To create a subcategory, just choose another category from the Parent dropdown.') . '</li>';
187
188         $help .= '<li>' . __('<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.') . '</li>' .
189                 '</ul>' .
190                 '<p>' . __('You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen and to display/hide columns in the table.') . '</p>' .
191                 '<p><strong>' . __('For more information:') . '</strong></p>';
192
193         if ( 'category' == $taxonomy )
194                 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Manage_Categories_SubPanel" target="_blank">Categories Documentation</a>') . '</p>';
195         else
196                 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Post_Tags_SubPanel" target="_blank">Tags Documentation</a>') . '</p>';
197
198         $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
199
200         add_contextual_help($current_screen, $help);
201         unset($help);
202 }
203
204 require_once ('admin-header.php');
205
206 $messages[1] = __('Item added.');
207 $messages[2] = __('Item deleted.');
208 $messages[3] = __('Item updated.');
209 $messages[4] = __('Item not added.');
210 $messages[5] = __('Item not updated.');
211 $messages[6] = __('Items deleted.');
212
213 ?>
214
215 <div class="wrap nosubsub">
216 <?php screen_icon(); ?>
217 <h2><?php echo esc_html( $title );
218 if ( !empty($_GET['s']) )
219         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
220 </h2>
221
222 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
223 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
224 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
225 endif; ?>
226 <div id="ajax-response"></div>
227
228 <form class="search-form" action="" method="get">
229 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
230 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
231 <p class="search-box">
232         <label class="screen-reader-text" for="tag-search-input"><?php echo $tax->labels->search_items; ?>:</label>
233         <input type="text" id="tag-search-input" name="s" value="<?php _admin_search_query(); ?>" />
234         <input type="submit" value="<?php echo esc_attr( $tax->labels->search_items );  ?>" class="button" />
235 </p>
236 </form>
237 <br class="clear" />
238
239 <div id="col-container">
240
241 <div id="col-right">
242 <div class="col-wrap">
243 <form id="posts-filter" action="" method="get">
244 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
245 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
246 <div class="tablenav">
247 <?php
248 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
249 if ( empty($pagenum) )
250         $pagenum = 1;
251
252 $tags_per_page = (int) get_user_option( 'edit_' .  $taxonomy . '_per_page' );
253
254 if ( empty($tags_per_page) || $tags_per_page < 1 )
255         $tags_per_page = 20;
256
257 if ( 'post_tag' == $taxonomy ) {
258         $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
259         $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
260 } elseif ( 'category' == $taxonomy ) {
261         $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
262 } else {
263         $tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page );
264 }
265
266 $searchterms = !empty($_GET['s']) ? trim(stripslashes($_GET['s'])) : '';
267
268 $page_links = paginate_links( array(
269         'base' => add_query_arg( 'pagenum', '%#%' ),
270         'format' => '',
271         'prev_text' => __('&laquo;'),
272         'next_text' => __('&raquo;'),
273         'total' => ceil(wp_count_terms($taxonomy, array('search' => $searchterms)) / $tags_per_page),
274         'current' => $pagenum
275 ));
276
277 if ( $page_links )
278         echo "<div class='tablenav-pages'>$page_links</div>";
279 ?>
280
281 <div class="alignleft actions">
282 <select name="action">
283 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
284 <option value="delete"><?php _e('Delete'); ?></option>
285 </select>
286 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
287 <?php wp_nonce_field('bulk-tags'); ?>
288 </div>
289
290 <br class="clear" />
291 </div>
292
293 <div class="clear"></div>
294 <table class="widefat tag fixed" cellspacing="0">
295         <thead>
296         <tr>
297 <?php print_column_headers($current_screen); ?>
298         </tr>
299         </thead>
300
301         <tfoot>
302         <tr>
303 <?php print_column_headers($current_screen, false); ?>
304         </tr>
305         </tfoot>
306
307         <tbody id="the-list" class="list:tag">
308 <?php tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy ); ?>
309         </tbody>
310 </table>
311
312 <div class="tablenav">
313 <?php
314 if ( $page_links )
315         echo "<div class='tablenav-pages'>$page_links</div>";
316 ?>
317
318 <div class="alignleft actions">
319 <select name="action2">
320 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
321 <option value="delete"><?php _e('Delete'); ?></option>
322 </select>
323 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
324 </div>
325
326 <br class="clear" />
327 </div>
328
329 <br class="clear" />
330 </form>
331
332 <?php if ( 'category' == $taxonomy ) : ?>
333 <div class="form-wrap">
334 <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_cat_name(get_option('default_category')))) ?></p>
335 <?php if ( current_user_can( 'import' ) ) : ?>
336 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
337 <?php endif; ?>
338 </div>
339 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
340 <div class="form-wrap">
341 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
342 </div>
343 <?php endif;
344 do_action('after-' . $taxonomy . '-table', $taxonomy);
345 ?>
346
347 </div>
348 </div><!-- /col-right -->
349
350 <div id="col-left">
351 <div class="col-wrap">
352
353 <?php
354
355 if ( !is_taxonomy_hierarchical($taxonomy) ) {
356         if ( current_user_can( $tax->cap->edit_terms ) )
357                 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
358         else
359                 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
360
361         if ( $tag_cloud ) :
362         ?>
363 <div class="tagcloud">
364 <h3><?php echo $tax->labels->popular_items; ?></h3>
365 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
366 </div>
367 <?php
368 endif;
369 }
370
371 if ( current_user_can($tax->cap->edit_terms) ) {
372         if ( 'category' == $taxonomy )
373                 do_action('add_category_form_pre', (object)array('parent' => 0) );  // Back compat hook. Deprecated in preference to $taxonomy_pre_add_form
374         else
375                 do_action('add_tag_form_pre', $taxonomy); // Back compat hook. Applies to all Taxonomies -not- categories
376         do_action($taxonomy . '_pre_add_form', $taxonomy);
377 ?>
378
379 <div class="form-wrap">
380 <h3><?php echo $tax->labels->add_new_item; ?></h3>
381 <form id="addtag" method="post" action="edit-tags.php" class="validate">
382 <input type="hidden" name="action" value="add-tag" />
383 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
384 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
385 <?php wp_nonce_field('add-tag'); ?>
386
387 <div class="form-field form-required">
388         <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
389         <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
390         <p><?php _e('The name is how it appears on your site.'); ?></p>
391 </div>
392 <?php if ( ! global_terms_enabled() ) : ?>
393 <div class="form-field">
394         <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
395         <input name="slug" id="tag-slug" type="text" value="" size="40" />
396         <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>
397 </div>
398 <?php endif; // is_multisite() ?>
399 <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
400 <div class="form-field">
401         <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
402         <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
403         <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
404                 <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>
405         <?php endif; ?>
406 </div>
407 <?php endif; // is_taxonomy_hierarchical() ?>
408 <div class="form-field">
409         <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
410         <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
411         <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
412 </div>
413
414 <?php
415 if ( ! is_taxonomy_hierarchical($taxonomy) )
416         do_action('add_tag_form_fields', $taxonomy);
417 do_action($taxonomy . '_add_form_fields', $taxonomy);
418 ?>
419 <p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" /></p>
420 <?php
421 if ( 'category' == $taxonomy )
422         do_action('edit_category_form', (object)array('parent' => 0) );  // Back compat hook. Deprecated in preference to $taxonomy_add_form
423 else
424         do_action('add_tag_form', $taxonomy); // Back compat hook. Applies to all Taxonomies -not- categories
425 do_action($taxonomy . '_add_form', $taxonomy);
426 ?>
427 </form></div>
428 <?php } ?>
429
430 </div>
431 </div><!-- /col-left -->
432
433 </div><!-- /col-container -->
434 </div><!-- /wrap -->
435
436 <?php inline_edit_term_row('edit-tags', $taxonomy); ?>
437
438 <?php
439 break;
440 }
441
442 include('./admin-footer.php');
443
444 ?>