3 * Edit Tags Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 wp_reset_vars( array('action', 'tag', 'taxonomy', 'post_type') );
14 if ( empty($taxonomy) )
15 $taxonomy = 'post_tag';
17 if ( !taxonomy_exists($taxonomy) )
18 wp_die(__('Invalid taxonomy'));
20 $tax = get_taxonomy($taxonomy);
22 if ( ! current_user_can($tax->cap->manage_terms) )
23 wp_die(__('Cheatin’ uh?'));
25 $title = $tax->labels->name;
27 if ( empty($post_type) || !in_array( $post_type, get_post_types( array('public' => true) ) ) )
30 if ( 'post' != $post_type ) {
31 $parent_file = "edit.php?post_type=$post_type";
32 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
34 $parent_file = 'edit.php';
35 $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
38 if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
39 $action = 'bulk-delete';
45 check_admin_referer('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( $_GET['tag_ID'] ) ) {
78 wp_redirect($location);
82 $tag_ID = (int) $_GET['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) $_GET['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 require_once ('admin-header.php');
125 $tag_ID = (int) $_GET['tag_ID'];
127 if ( !current_user_can($tax->cap->edit_terms) )
128 wp_die( __('You are not allowed to edit this item.') );
130 $tag = get_term($tag_ID, $taxonomy, OBJECT, 'edit');
131 include('./edit-tag-form.php');
136 $tag_ID = (int) $_POST['tag_ID'];
137 check_admin_referer('update-tag_' . $tag_ID);
139 if ( !current_user_can($tax->cap->edit_terms) )
140 wp_die(__('Cheatin’ uh?'));
142 $ret = wp_update_term($tag_ID, $taxonomy, $_POST);
144 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
145 if ( 'post' != $post_type )
146 $location .= '&post_type=' . $post_type;
148 if ( $referer = wp_get_original_referer() ) {
149 if ( false !== strpos($referer, 'edit-tags.php') )
150 $location = $referer;
153 if ( $ret && !is_wp_error( $ret ) )
154 $location = add_query_arg('message', 3, $location);
156 $location = add_query_arg('message', 5, $location);
158 wp_redirect($location);
164 if ( ! empty($_GET['_wp_http_referer']) ) {
165 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
169 wp_enqueue_script('admin-tags');
170 if ( current_user_can($tax->cap->edit_terms) )
171 wp_enqueue_script('inline-edit-tax');
173 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) {
174 if ( 'category' == $taxonomy )
175 $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>';
177 $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>';
179 $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>';
181 if ( 'category' == $taxonomy )
182 $help .= '<p>' . __('When adding a new category on this screen, you’ll fill in the following fields:') . '</p>';
184 $help .= '<p>' . __('When adding a new tag on this screen, you’ll fill in the following fields:') . '</p>';
187 '<li>' . __('<strong>Name</strong> - The name is how it appears on your site.') . '</li>';
188 if ( ! global_terms_enabled() )
189 $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>';
191 if ( 'category' == $taxonomy )
192 $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>';
194 $help .= '<li>' . __('<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.') . '</li>' .
196 '<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>' .
197 '<p><strong>' . __('For more information:') . '</strong></p>';
199 if ( 'category' == $taxonomy )
200 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Manage_Categories_SubPanel" target="_blank">Categories Documentation</a>') . '</p>';
202 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Post_Tags_SubPanel" target="_blank">Tags Documentation</a>') . '</p>';
204 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
206 add_contextual_help($current_screen, $help);
210 require_once ('admin-header.php');
212 $messages[1] = __('Item added.');
213 $messages[2] = __('Item deleted.');
214 $messages[3] = __('Item updated.');
215 $messages[4] = __('Item not added.');
216 $messages[5] = __('Item not updated.');
217 $messages[6] = __('Items deleted.');
221 <div class="wrap nosubsub">
222 <?php screen_icon(); ?>
223 <h2><?php echo esc_html( $title );
224 if ( !empty($_GET['s']) )
225 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
228 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
229 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
230 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
232 <div id="ajax-response"></div>
234 <form class="search-form" action="" method="get">
235 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
236 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
237 <p class="search-box">
238 <label class="screen-reader-text" for="tag-search-input"><?php echo $tax->labels->search_items; ?>:</label>
239 <input type="text" id="tag-search-input" name="s" value="<?php _admin_search_query(); ?>" />
240 <input type="submit" value="<?php echo esc_attr( $tax->labels->search_items ); ?>" class="button" />
245 <div id="col-container">
248 <div class="col-wrap">
249 <form id="posts-filter" action="" method="get">
250 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
251 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
252 <div class="tablenav">
254 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
255 if ( empty($pagenum) )
258 $tags_per_page = (int) get_user_option( 'edit_' . $taxonomy . '_per_page' );
260 if ( empty($tags_per_page) || $tags_per_page < 1 )
263 if ( 'post_tag' == $taxonomy ) {
264 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
265 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
266 } elseif ( 'category' == $taxonomy ) {
267 $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
269 $tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page );
272 $searchterms = !empty($_GET['s']) ? trim(stripslashes($_GET['s'])) : '';
274 $page_links = paginate_links( array(
275 'base' => add_query_arg( 'pagenum', '%#%' ),
277 'prev_text' => __('«'),
278 'next_text' => __('»'),
279 'total' => ceil(wp_count_terms($taxonomy, array('search' => $searchterms)) / $tags_per_page),
280 'current' => $pagenum
284 echo "<div class='tablenav-pages'>$page_links</div>";
287 <div class="alignleft actions">
288 <select name="action">
289 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
290 <option value="delete"><?php _e('Delete'); ?></option>
292 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
293 <?php wp_nonce_field('bulk-tags'); ?>
299 <div class="clear"></div>
300 <table class="widefat tag fixed" cellspacing="0">
303 <?php print_column_headers($current_screen); ?>
309 <?php print_column_headers($current_screen, false); ?>
313 <tbody id="the-list" class="list:tag">
314 <?php tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy ); ?>
318 <div class="tablenav">
321 echo "<div class='tablenav-pages'>$page_links</div>";
324 <div class="alignleft actions">
325 <select name="action2">
326 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
327 <option value="delete"><?php _e('Delete'); ?></option>
329 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
338 <?php if ( 'category' == $taxonomy ) : ?>
339 <div class="form-wrap">
340 <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>
341 <?php if ( current_user_can( 'import' ) ) : ?>
342 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
345 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
346 <div class="form-wrap">
347 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
350 do_action('after-' . $taxonomy . '-table', $taxonomy);
354 </div><!-- /col-right -->
357 <div class="col-wrap">
361 if ( !is_taxonomy_hierarchical($taxonomy) ) {
362 if ( current_user_can( $tax->cap->edit_terms ) )
363 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
365 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
369 <div class="tagcloud">
370 <h3><?php echo $tax->labels->popular_items; ?></h3>
371 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
377 if ( current_user_can($tax->cap->edit_terms) ) {
378 if ( 'category' == $taxonomy )
379 do_action('add_category_form_pre', (object)array('parent' => 0) ); // Back compat hook. Deprecated in preference to $taxonomy_pre_add_form
381 do_action('add_tag_form_pre', $taxonomy); // Back compat hook. Applies to all Taxonomies -not- categories
382 do_action($taxonomy . '_pre_add_form', $taxonomy);
385 <div class="form-wrap">
386 <h3><?php echo $tax->labels->add_new_item; ?></h3>
387 <form id="addtag" method="post" action="edit-tags.php" class="validate">
388 <input type="hidden" name="action" value="add-tag" />
389 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
390 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
391 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
392 <?php wp_nonce_field('add-tag'); ?>
394 <div class="form-field form-required">
395 <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
396 <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
397 <p><?php _e('The name is how it appears on your site.'); ?></p>
399 <?php if ( ! global_terms_enabled() ) : ?>
400 <div class="form-field">
401 <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
402 <input name="slug" id="tag-slug" type="text" value="" size="40" />
403 <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>
405 <?php endif; // is_multisite() ?>
406 <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
407 <div class="form-field">
408 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
409 <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
410 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
411 <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>
414 <?php endif; // is_taxonomy_hierarchical() ?>
415 <div class="form-field">
416 <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
417 <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
418 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
422 if ( ! is_taxonomy_hierarchical($taxonomy) )
423 do_action('add_tag_form_fields', $taxonomy);
424 do_action($taxonomy . '_add_form_fields', $taxonomy);
426 <p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" /></p>
428 if ( 'category' == $taxonomy )
429 do_action('edit_category_form', (object)array('parent' => 0) ); // Back compat hook. Deprecated in preference to $taxonomy_add_form
431 do_action('add_tag_form', $taxonomy); // Back compat hook. Applies to all Taxonomies -not- categories
432 do_action($taxonomy . '_add_form', $taxonomy);
438 </div><!-- /col-left -->
440 </div><!-- /col-container -->
443 <?php inline_edit_term_row('edit-tags', $taxonomy); ?>
449 include('./admin-footer.php');