3 * Edit Tags Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
11 $tax = get_taxonomy( $taxnow );
12 if ( !current_user_can( $tax->cap->manage_terms ) )
13 wp_die( __( 'Cheatin’ uh?' ) );
15 $wp_list_table = _get_list_table('WP_Terms_List_Table');
16 $pagenum = $wp_list_table->get_pagenum();
18 $title = $tax->labels->name;
20 if ( 'post' != $post_type ) {
21 $parent_file = "edit.php?post_type=$post_type";
22 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
23 } else if ( 'link_category' == $tax->name ) {
24 $parent_file = 'link-manager.php';
25 $submenu_file = 'edit-tags.php?taxonomy=link_category';
27 $parent_file = 'edit.php';
28 $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
31 add_screen_option( 'per_page', array('label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page') );
33 switch ( $wp_list_table->current_action() ) {
37 check_admin_referer( 'add-tag' );
39 if ( !current_user_can( $tax->cap->edit_terms ) )
40 wp_die( __( 'Cheatin’ uh?' ) );
42 $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
43 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
44 if ( 'post' != $post_type )
45 $location .= '&post_type=' . $post_type;
47 if ( $referer = wp_get_original_referer() ) {
48 if ( false !== strpos( $referer, 'edit-tags.php' ) )
52 if ( $ret && !is_wp_error( $ret ) )
53 $location = add_query_arg( 'message', 1, $location );
55 $location = add_query_arg( 'message', 4, $location );
56 wp_redirect( $location );
61 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
62 if ( 'post' != $post_type )
63 $location .= '&post_type=' . $post_type;
64 if ( $referer = wp_get_referer() ) {
65 if ( false !== strpos( $referer, 'edit-tags.php' ) )
69 if ( !isset( $_REQUEST['tag_ID'] ) ) {
70 wp_redirect( $location );
74 $tag_ID = (int) $_REQUEST['tag_ID'];
75 check_admin_referer( 'delete-tag_' . $tag_ID );
77 if ( !current_user_can( $tax->cap->delete_terms ) )
78 wp_die( __( 'Cheatin’ uh?' ) );
80 wp_delete_term( $tag_ID, $taxonomy );
82 $location = add_query_arg( 'message', 2, $location );
83 wp_redirect( $location );
89 check_admin_referer( 'bulk-tags' );
91 if ( !current_user_can( $tax->cap->delete_terms ) )
92 wp_die( __( 'Cheatin’ uh?' ) );
94 $tags = (array) $_REQUEST['delete_tags'];
95 foreach ( $tags as $tag_ID ) {
96 wp_delete_term( $tag_ID, $taxonomy );
99 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
100 if ( 'post' != $post_type )
101 $location .= '&post_type=' . $post_type;
102 if ( $referer = wp_get_referer() ) {
103 if ( false !== strpos( $referer, 'edit-tags.php' ) )
104 $location = $referer;
107 $location = add_query_arg( 'message', 6, $location );
108 wp_redirect( $location );
114 $title = $tax->labels->edit_item;
116 require_once ( 'admin-header.php' );
117 $tag_ID = (int) $_REQUEST['tag_ID'];
119 $tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' );
120 include( './edit-tag-form.php' );
125 $tag_ID = (int) $_POST['tag_ID'];
126 check_admin_referer( 'update-tag_' . $tag_ID );
128 if ( !current_user_can( $tax->cap->edit_terms ) )
129 wp_die( __( 'Cheatin’ uh?' ) );
131 $ret = wp_update_term( $tag_ID, $taxonomy, $_POST );
133 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
134 if ( 'post' != $post_type )
135 $location .= '&post_type=' . $post_type;
137 if ( $referer = wp_get_original_referer() ) {
138 if ( false !== strpos( $referer, 'edit-tags.php' ) )
139 $location = $referer;
142 if ( $ret && !is_wp_error( $ret ) )
143 $location = add_query_arg( 'message', 3, $location );
145 $location = add_query_arg( 'message', 5, $location );
147 wp_redirect( $location );
152 if ( ! empty($_REQUEST['_wp_http_referer']) ) {
153 $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) );
155 if ( ! empty( $_REQUEST['paged'] ) )
156 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'] );
158 wp_redirect( $location );
162 $wp_list_table->prepare_items();
163 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
165 if ( $pagenum > $total_pages && $total_pages > 0 ) {
166 wp_redirect( add_query_arg( 'paged', $total_pages ) );
170 wp_enqueue_script('admin-tags');
171 if ( current_user_can($tax->cap->edit_terms) )
172 wp_enqueue_script('inline-edit-tax');
174 if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) {
176 if ( 'category' == $taxonomy )
177 $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>';
178 elseif ( 'link_category' == $taxonomy )
179 $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>';
181 $help = '<p>' . __( 'You can assign keywords to your posts using Post Tags. Unlike categories, tags have no hierarchy, meaning there’s no relationship from one tag to another.' ) . '</p>';
183 if ( 'link_category' == $taxonomy )
184 $help .= '<p>' . __( 'You can delete link categories in the Bulk Action pulldown, but that action does not delete the links within the category. Instead, it moves them to the default link category.' ) . '</p>';
186 $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>';
188 if ( 'category' == $taxonomy )
189 $help .= '<p>' . __( 'When adding a new category on this screen, you’ll fill in the following fields:' ) . '</p>';
190 elseif ( 'post_tag' == $taxonomy )
191 $help .= '<p>' . __( 'When adding a new tag on this screen, you’ll fill in the following fields:' ) . '</p>';
193 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy )
196 '<li>' . __( '<strong>Name</strong> - The name is how it appears on your site.' ) . '</li>';
198 if ( ! global_terms_enabled() )
199 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy )
200 $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>';
202 if ( 'category' == $taxonomy )
203 $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>';
205 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy )
206 $help .= '<li>' . __( '<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.' ) . '</li>' .
208 '<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>' .
209 '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
211 if ( 'category' == $taxonomy )
212 $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Categories_SubPanel" target="_blank">Documentation on Categories</a>' ) . '</p>';
213 elseif ( 'link_category' == $taxonomy )
214 $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Links_Link_Categories_SubPanel" target="_blank">Documentation on Link Categories</a>' ) . '</p>';
216 $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Post_Tags_SubPanel" target="_blank">Documentation on Post Tags</a>' ) . '</p>';
218 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
220 add_contextual_help($current_screen, $help);
224 require_once ('admin-header.php');
226 if ( !current_user_can($tax->cap->edit_terms) )
227 wp_die( __('You are not allowed to edit this item.') );
229 $messages[1] = __('Item added.');
230 $messages[2] = __('Item deleted.');
231 $messages[3] = __('Item updated.');
232 $messages[4] = __('Item not added.');
233 $messages[5] = __('Item not updated.');
234 $messages[6] = __('Items deleted.');
238 <div class="wrap nosubsub">
239 <?php screen_icon(); ?>
240 <h2><?php echo esc_html( $title );
241 if ( !empty($_REQUEST['s']) )
242 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
245 <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
246 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
247 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
249 <div id="ajax-response"></div>
251 <form class="search-form" action="" method="get">
252 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
253 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
255 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
260 <div id="col-container">
263 <div class="col-wrap">
264 <form id="posts-filter" action="" method="post">
265 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
266 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
268 <?php $wp_list_table->display(); ?>
273 <?php if ( 'category' == $taxonomy ) : ?>
274 <div class="form-wrap">
275 <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>
276 <?php if ( current_user_can( 'import' ) ) : ?>
277 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
280 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
281 <div class="form-wrap">
282 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
285 do_action('after-' . $taxonomy . '-table', $taxonomy);
289 </div><!-- /col-right -->
292 <div class="col-wrap">
296 if ( !is_null( $tax->labels->popular_items ) ) {
297 if ( current_user_can( $tax->cap->edit_terms ) )
298 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
300 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
304 <div class="tagcloud">
305 <h3><?php echo $tax->labels->popular_items; ?></h3>
306 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
312 if ( current_user_can($tax->cap->edit_terms) ) {
313 // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
314 if ( 'category' == $taxonomy )
315 do_action('add_category_form_pre', (object)array('parent' => 0) );
316 elseif ( 'link_category' == $taxonomy )
317 do_action('add_link_category_form_pre', (object)array('parent' => 0) );
319 do_action('add_tag_form_pre', $taxonomy);
321 do_action($taxonomy . '_pre_add_form', $taxonomy);
324 <div class="form-wrap">
325 <h3><?php echo $tax->labels->add_new_item; ?></h3>
326 <form id="addtag" method="post" action="edit-tags.php" class="validate">
327 <input type="hidden" name="action" value="add-tag" />
328 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
329 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
330 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
331 <?php wp_nonce_field('add-tag'); ?>
333 <div class="form-field form-required">
334 <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
335 <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
336 <p><?php _e('The name is how it appears on your site.'); ?></p>
338 <?php if ( ! global_terms_enabled() ) : ?>
339 <div class="form-field">
340 <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
341 <input name="slug" id="tag-slug" type="text" value="" size="40" />
342 <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>
344 <?php endif; // global_terms_enabled() ?>
345 <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
346 <div class="form-field">
347 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
348 <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
349 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
350 <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>
353 <?php endif; // is_taxonomy_hierarchical() ?>
354 <div class="form-field">
355 <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
356 <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
357 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
361 if ( ! is_taxonomy_hierarchical($taxonomy) )
362 do_action('add_tag_form_fields', $taxonomy);
363 do_action($taxonomy . '_add_form_fields', $taxonomy);
365 submit_button( $tax->labels->add_new_item, 'button' );
367 // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
368 if ( 'category' == $taxonomy )
369 do_action('edit_category_form', (object)array('parent' => 0) );
370 elseif ( 'link_category' == $taxonomy )
371 do_action('edit_link_category_form', (object)array('parent' => 0) );
373 do_action('add_tag_form', $taxonomy);
375 do_action($taxonomy . '_add_form', $taxonomy);
381 </div><!-- /col-left -->
383 </div><!-- /col-container -->
386 <?php $wp_list_table->inline_edit(); ?>
392 include('./admin-footer.php');