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 $title = $tax->labels->name;
24 if ( empty($post_type) || !in_array( $post_type, get_post_types( array('public' => true) ) ) )
27 if ( 'post' != $post_type ) {
28 $parent_file = "edit.php?post_type=$post_type";
29 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
31 $parent_file = 'edit.php';
32 $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
35 if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
36 $action = 'bulk-delete';
42 check_admin_referer('add-tag');
44 if ( !current_user_can($tax->cap->edit_terms) )
45 wp_die(__('Cheatin’ uh?'));
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;
52 if ( $referer = wp_get_original_referer() ) {
53 if ( false !== strpos($referer, 'edit-tags.php') )
57 if ( $ret && !is_wp_error( $ret ) )
58 $location = add_query_arg('message', 1, $location);
60 $location = add_query_arg('message', 4, $location);
61 wp_redirect($location);
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') )
74 if ( !isset( $_GET['tag_ID'] ) ) {
75 wp_redirect($location);
79 $tag_ID = (int) $_GET['tag_ID'];
80 check_admin_referer('delete-tag_' . $tag_ID);
82 if ( !current_user_can($tax->cap->delete_terms) )
83 wp_die(__('Cheatin’ uh?'));
85 wp_delete_term( $tag_ID, $taxonomy);
87 $location = add_query_arg('message', 2, $location);
88 wp_redirect($location);
94 check_admin_referer('bulk-tags');
96 if ( !current_user_can($tax->cap->delete_terms) )
97 wp_die(__('Cheatin’ uh?'));
99 $tags = (array) $_GET['delete_tags'];
100 foreach( $tags as $tag_ID ) {
101 wp_delete_term( $tag_ID, $taxonomy);
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;
112 $location = add_query_arg('message', 6, $location);
113 wp_redirect($location);
119 $title = $tax->labels->edit_item;
121 require_once ('admin-header.php');
122 $tag_ID = (int) $_GET['tag_ID'];
124 $tag = get_term($tag_ID, $taxonomy, OBJECT, 'edit');
125 include('./edit-tag-form.php');
130 $tag_ID = (int) $_POST['tag_ID'];
131 check_admin_referer('update-tag_' . $tag_ID);
133 if ( !current_user_can($tax->cap->edit_terms) )
134 wp_die(__('Cheatin’ uh?'));
136 $ret = wp_update_term($tag_ID, $taxonomy, $_POST);
138 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
139 if ( 'post' != $post_type )
140 $location .= '&post_type=' . $post_type;
142 if ( $referer = wp_get_original_referer() ) {
143 if ( false !== strpos($referer, 'edit-tags.php') )
144 $location = $referer;
147 if ( $ret && !is_wp_error( $ret ) )
148 $location = add_query_arg('message', 3, $location);
150 $location = add_query_arg('message', 5, $location);
152 wp_redirect($location);
158 if ( ! empty($_GET['_wp_http_referer']) ) {
159 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
163 wp_enqueue_script('admin-tags');
164 if ( current_user_can($tax->cap->edit_terms) )
165 wp_enqueue_script('inline-edit-tax');
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 “Uncategorized” until you change it in your <a href="%s">writing settings</a>.'), 'options-writing.php') . '</p>';
171 $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>';
173 $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>';
175 if ( 'category' == $taxonomy )
176 $help .= '<p>' . __('When adding a new category on this screen, you’ll fill in the following fields:') . '</p>';
178 $help .= '<p>' . __('When adding a new tag on this screen, you’ll fill in the following fields:') . '</p>';
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 “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.') . '</li>';
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>';
188 $help .= '<li>' . __('<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.') . '</li>' .
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>';
193 if ( 'category' == $taxonomy )
194 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Manage_Categories_SubPanel" target="_blank">Categories Documentation</a>') . '</p>';
196 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Post_Tags_SubPanel" target="_blank">Tags Documentation</a>') . '</p>';
198 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
200 add_contextual_help($current_screen, $help);
204 require_once ('admin-header.php');
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.');
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 “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
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']);
226 <div id="ajax-response"></div>
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" />
239 <div id="col-container">
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">
248 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
249 if ( empty($pagenum) )
252 $tags_per_page = (int) get_user_option( 'edit_' . $taxonomy . '_per_page' );
254 if ( empty($tags_per_page) || $tags_per_page < 1 )
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
263 $tags_per_page = apply_filters( 'edit_' . $taxonomy . '_per_page', $tags_per_page );
266 $searchterms = !empty($_GET['s']) ? trim(stripslashes($_GET['s'])) : '';
268 $page_links = paginate_links( array(
269 'base' => add_query_arg( 'pagenum', '%#%' ),
271 'prev_text' => __('«'),
272 'next_text' => __('»'),
273 'total' => ceil(wp_count_terms($taxonomy, array('search' => $searchterms)) / $tags_per_page),
274 'current' => $pagenum
278 echo "<div class='tablenav-pages'>$page_links</div>";
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>
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'); ?>
293 <div class="clear"></div>
294 <table class="widefat tag fixed" cellspacing="0">
297 <?php print_column_headers($current_screen); ?>
303 <?php print_column_headers($current_screen, false); ?>
307 <tbody id="the-list" class="list:tag">
308 <?php tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy ); ?>
312 <div class="tablenav">
315 echo "<div class='tablenav-pages'>$page_links</div>";
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>
323 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
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>
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>
344 do_action('after-' . $taxonomy . '-table', $taxonomy);
348 </div><!-- /col-right -->
351 <div class="col-wrap">
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' ) );
359 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
363 <div class="tagcloud">
364 <h3><?php echo $tax->labels->popular_items; ?></h3>
365 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
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
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);
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'); ?>
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>
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 “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
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>
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>
415 if ( ! is_taxonomy_hierarchical($taxonomy) )
416 do_action('add_tag_form_fields', $taxonomy);
417 do_action($taxonomy . '_add_form_fields', $taxonomy);
419 <p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" /></p>
421 if ( 'category' == $taxonomy )
422 do_action('edit_category_form', (object)array('parent' => 0) ); // Back compat hook. Deprecated in preference to $taxonomy_add_form
424 do_action('add_tag_form', $taxonomy); // Back compat hook. Applies to all Taxonomies -not- categories
425 do_action($taxonomy . '_add_form', $taxonomy);
431 </div><!-- /col-left -->
433 </div><!-- /col-container -->
436 <?php inline_edit_term_row('edit-tags', $taxonomy); ?>
442 include('./admin-footer.php');