3 * Edit Tags Administration Screen.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
13 wp_die( __( 'Invalid taxonomy' ) );
15 $tax = get_taxonomy( $taxnow );
18 wp_die( __( 'Invalid taxonomy' ) );
20 if ( ! current_user_can( $tax->cap->manage_terms ) )
21 wp_die( __( 'Cheatin’ uh?' ) );
23 $wp_list_table = _get_list_table('WP_Terms_List_Table');
24 $pagenum = $wp_list_table->get_pagenum();
26 $title = $tax->labels->name;
28 if ( 'post' != $post_type ) {
29 $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type";
30 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
31 } else if ( 'link_category' == $tax->name ) {
32 $parent_file = 'link-manager.php';
33 $submenu_file = 'edit-tags.php?taxonomy=link_category';
35 $parent_file = 'edit.php';
36 $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
39 add_screen_option( 'per_page', array( 'label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) );
41 switch ( $wp_list_table->current_action() ) {
45 check_admin_referer( 'add-tag', '_wpnonce_add-tag' );
47 if ( !current_user_can( $tax->cap->edit_terms ) )
48 wp_die( __( 'Cheatin’ uh?' ) );
50 $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
51 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
52 if ( 'post' != $post_type )
53 $location .= '&post_type=' . $post_type;
55 if ( $referer = wp_get_original_referer() ) {
56 if ( false !== strpos( $referer, 'edit-tags.php' ) )
60 if ( $ret && !is_wp_error( $ret ) )
61 $location = add_query_arg( 'message', 1, $location );
63 $location = add_query_arg( 'message', 4, $location );
64 wp_redirect( $location );
69 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
70 if ( 'post' != $post_type )
71 $location .= '&post_type=' . $post_type;
72 if ( $referer = wp_get_referer() ) {
73 if ( false !== strpos( $referer, 'edit-tags.php' ) )
77 if ( !isset( $_REQUEST['tag_ID'] ) ) {
78 wp_redirect( $location );
82 $tag_ID = (int) $_REQUEST['tag_ID'];
83 check_admin_referer( 'delete-tag_' . $tag_ID );
85 if ( !current_user_can( $tax->cap->delete_terms ) )
86 wp_die( __( 'Cheatin’ uh?' ) );
88 wp_delete_term( $tag_ID, $taxonomy );
90 $location = add_query_arg( 'message', 2, $location );
91 wp_redirect( $location );
97 check_admin_referer( 'bulk-tags' );
99 if ( !current_user_can( $tax->cap->delete_terms ) )
100 wp_die( __( 'Cheatin’ uh?' ) );
102 $tags = (array) $_REQUEST['delete_tags'];
103 foreach ( $tags as $tag_ID ) {
104 wp_delete_term( $tag_ID, $taxonomy );
107 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
108 if ( 'post' != $post_type )
109 $location .= '&post_type=' . $post_type;
110 if ( $referer = wp_get_referer() ) {
111 if ( false !== strpos( $referer, 'edit-tags.php' ) )
112 $location = $referer;
115 $location = add_query_arg( 'message', 6, $location );
116 wp_redirect( $location );
122 $title = $tax->labels->edit_item;
124 $tag_ID = (int) $_REQUEST['tag_ID'];
126 $tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' );
128 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
129 require_once( ABSPATH . 'wp-admin/admin-header.php' );
130 include( ABSPATH . 'wp-admin/edit-tag-form.php' );
135 $tag_ID = (int) $_POST['tag_ID'];
136 check_admin_referer( 'update-tag_' . $tag_ID );
138 if ( !current_user_can( $tax->cap->edit_terms ) )
139 wp_die( __( 'Cheatin’ uh?' ) );
141 $tag = get_term( $tag_ID, $taxonomy );
143 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
145 $ret = wp_update_term( $tag_ID, $taxonomy, $_POST );
147 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
148 if ( 'post' != $post_type )
149 $location .= '&post_type=' . $post_type;
151 if ( $referer = wp_get_original_referer() ) {
152 if ( false !== strpos( $referer, 'edit-tags.php' ) )
153 $location = $referer;
156 if ( $ret && !is_wp_error( $ret ) )
157 $location = add_query_arg( 'message', 3, $location );
159 $location = add_query_arg( 'message', 5, $location );
161 wp_redirect( $location );
166 if ( ! empty($_REQUEST['_wp_http_referer']) ) {
167 $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']) );
169 if ( ! empty( $_REQUEST['paged'] ) )
170 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'] );
172 wp_redirect( $location );
176 $wp_list_table->prepare_items();
177 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
179 if ( $pagenum > $total_pages && $total_pages > 0 ) {
180 wp_redirect( add_query_arg( 'paged', $total_pages ) );
184 wp_enqueue_script('admin-tags');
185 if ( current_user_can($tax->cap->edit_terms) )
186 wp_enqueue_script('inline-edit-tax');
188 if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) {
190 if ( 'category' == $taxonomy )
191 $help = '<p>' . sprintf(__( 'You can use categories to define sections of your site and group related posts. The default category is “Uncategorized” until you change it in your <a href="%s">writing settings</a>.' ) , 'options-writing.php' ) . '</p>';
192 elseif ( 'link_category' == $taxonomy )
193 $help = '<p>' . __( 'You can create groups of links by using Link Categories. Link Category names must be unique and Link Categories are separate from the categories you use for posts.' ) . '</p>';
195 $help = '<p>' . __( 'You can assign keywords to your posts using <strong>tags</strong>. Unlike categories, tags have no hierarchy, meaning there’s no relationship from one tag to another.' ) . '</p>';
197 if ( 'link_category' == $taxonomy )
198 $help .= '<p>' . __( 'You can delete Link Categories in the Bulk Action pull-down, but that action does not delete the links within the category. Instead, it moves them to the default Link Category.' ) . '</p>';
200 $help .='<p>' . __( 'What’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>';
202 get_current_screen()->add_help_tab( array(
204 'title' => __('Overview'),
208 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) {
209 if ( 'category' == $taxonomy )
210 $help = '<p>' . __( 'When adding a new category on this screen, you’ll fill in the following fields:' ) . '</p>';
212 $help = '<p>' . __( 'When adding a new tag on this screen, you’ll fill in the following fields:' ) . '</p>';
215 '<li>' . __( '<strong>Name</strong> - The name is how it appears on your site.' ) . '</li>';
217 if ( ! global_terms_enabled() )
218 $help .= '<li>' . __( '<strong>Slug</strong> - The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' ) . '</li>';
220 if ( 'category' == $taxonomy )
221 $help .= '<li>' . __( '<strong>Parent</strong> - Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have child categories for Bebop and Big Band. Totally optional. To create a subcategory, just choose another category from the Parent dropdown.' ) . '</li>';
223 $help .= '<li>' . __( '<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.' ) . '</li>' .
225 '<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>';
227 get_current_screen()->add_help_tab( array(
228 'id' => 'adding-terms',
229 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ),
234 $help = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
236 if ( 'category' == $taxonomy )
237 $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Categories_Screen" target="_blank">Documentation on Categories</a>' ) . '</p>';
238 elseif ( 'link_category' == $taxonomy )
239 $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Links_Link_Categories_Screen" target="_blank">Documentation on Link Categories</a>' ) . '</p>';
241 $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Tags_Screen" target="_blank">Documentation on Tags</a>' ) . '</p>';
243 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
245 get_current_screen()->set_help_sidebar( $help );
250 require_once( ABSPATH . 'wp-admin/admin-header.php' );
252 if ( !current_user_can($tax->cap->edit_terms) )
253 wp_die( __('You are not allowed to edit this item.') );
256 $messages['_item'] = array(
257 0 => '', // Unused. Messages start at index 1.
258 1 => __( 'Item added.' ),
259 2 => __( 'Item deleted.' ),
260 3 => __( 'Item updated.' ),
261 4 => __( 'Item not added.' ),
262 5 => __( 'Item not updated.' ),
263 6 => __( 'Items deleted.' )
265 $messages['category'] = array(
266 0 => '', // Unused. Messages start at index 1.
267 1 => __( 'Category added.' ),
268 2 => __( 'Category deleted.' ),
269 3 => __( 'Category updated.' ),
270 4 => __( 'Category not added.' ),
271 5 => __( 'Category not updated.' ),
272 6 => __( 'Categories deleted.' )
274 $messages['post_tag'] = array(
275 0 => '', // Unused. Messages start at index 1.
276 1 => __( 'Tag added.' ),
277 2 => __( 'Tag deleted.' ),
278 3 => __( 'Tag updated.' ),
279 4 => __( 'Tag not added.' ),
280 5 => __( 'Tag not updated.' ),
281 6 => __( 'Tags deleted.' )
284 $messages = apply_filters( 'term_updated_messages', $messages );
287 if ( isset( $_REQUEST['message'] ) && ( $msg = (int) $_REQUEST['message'] ) ) {
288 if ( isset( $messages[ $taxonomy ][ $msg ] ) )
289 $message = $messages[ $taxonomy ][ $msg ];
290 elseif ( ! isset( $messages[ $taxonomy ] ) && isset( $messages['_item'][ $msg ] ) )
291 $message = $messages['_item'][ $msg ];
296 <div class="wrap nosubsub">
297 <?php screen_icon(); ?>
298 <h2><?php echo esc_html( $title );
299 if ( !empty($_REQUEST['s']) )
300 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( wp_unslash($_REQUEST['s']) ) ); ?>
303 <?php if ( $message ) : ?>
304 <div id="message" class="updated"><p><?php echo $message; ?></p></div>
305 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
307 <div id="ajax-response"></div>
309 <form class="search-form" action="" method="get">
310 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
311 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
313 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
318 <div id="col-container">
321 <div class="col-wrap">
322 <form id="posts-filter" action="" method="post">
323 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
324 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
326 <?php $wp_list_table->display(); ?>
331 <?php if ( 'category' == $taxonomy ) : ?>
332 <div class="form-wrap">
333 <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>
334 <?php if ( current_user_can( 'import' ) ) : ?>
335 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
338 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
339 <div class="form-wrap">
340 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>.'), 'import.php') ;?></p>
343 do_action('after-' . $taxonomy . '-table', $taxonomy);
347 </div><!-- /col-right -->
350 <div class="col-wrap">
354 if ( !is_null( $tax->labels->popular_items ) ) {
355 if ( current_user_can( $tax->cap->edit_terms ) )
356 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
358 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
362 <div class="tagcloud">
363 <h3><?php echo $tax->labels->popular_items; ?></h3>
364 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
370 if ( current_user_can($tax->cap->edit_terms) ) {
371 // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
372 if ( 'category' == $taxonomy )
373 do_action('add_category_form_pre', (object)array('parent' => 0) );
374 elseif ( 'link_category' == $taxonomy )
375 do_action('add_link_category_form_pre', (object)array('parent' => 0) );
377 do_action('add_tag_form_pre', $taxonomy);
379 do_action($taxonomy . '_pre_add_form', $taxonomy);
382 <div class="form-wrap">
383 <h3><?php echo $tax->labels->add_new_item; ?></h3>
384 <form id="addtag" method="post" action="edit-tags.php" class="validate"<?php do_action( $taxonomy . '_term_new_form_tag' ); ?>>
385 <input type="hidden" name="action" value="add-tag" />
386 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
387 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
388 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
389 <?php wp_nonce_field('add-tag', '_wpnonce_add-tag'); ?>
391 <div class="form-field form-required">
392 <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
393 <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
394 <p><?php _e('The name is how it appears on your site.'); ?></p>
396 <?php if ( ! global_terms_enabled() ) : ?>
397 <div class="form-field">
398 <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
399 <input name="slug" id="tag-slug" type="text" value="" size="40" />
400 <p><?php _e('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
402 <?php endif; // global_terms_enabled() ?>
403 <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
404 <div class="form-field">
405 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
407 $dropdown_args = array(
409 'hide_if_empty' => false,
410 'taxonomy' => $taxonomy,
413 'hierarchical' => true,
414 'show_option_none' => __( 'None' ),
417 $dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy );
418 wp_dropdown_categories( $dropdown_args );
420 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
421 <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>
424 <?php endif; // is_taxonomy_hierarchical() ?>
425 <div class="form-field">
426 <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
427 <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
428 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
432 if ( ! is_taxonomy_hierarchical($taxonomy) )
433 do_action('add_tag_form_fields', $taxonomy);
434 do_action($taxonomy . '_add_form_fields', $taxonomy);
436 submit_button( $tax->labels->add_new_item );
438 // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
439 if ( 'category' == $taxonomy )
440 do_action('edit_category_form', (object)array('parent' => 0) );
441 elseif ( 'link_category' == $taxonomy )
442 do_action('edit_link_category_form', (object)array('parent' => 0) );
444 do_action('add_tag_form', $taxonomy);
446 do_action($taxonomy . '_add_form', $taxonomy);
452 </div><!-- /col-left -->
454 </div><!-- /col-container -->
456 <script type="text/javascript">
457 try{document.forms.addtag['tag-name'].focus();}catch(e){}
459 <?php $wp_list_table->inline_edit(); ?>
465 include( ABSPATH . 'wp-admin/admin-footer.php' );