3 * Edit Tags Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
14 wp_reset_vars( array('action', 'tag', 'taxonomy') );
16 if ( empty($taxonomy) )
17 $taxonomy = 'post_tag';
19 if ( !is_taxonomy($taxonomy) )
20 wp_die(__('Invalid taxonomy'));
22 $parent_file = 'edit.php';
23 $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
25 if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
26 $action = 'bulk-delete';
32 check_admin_referer('add-tag');
34 if ( !current_user_can('manage_categories') )
35 wp_die(__('Cheatin’ uh?'));
37 $ret = wp_insert_term($_POST['name'], $taxonomy, $_POST);
38 if ( $ret && !is_wp_error( $ret ) ) {
39 wp_redirect('edit-tags.php?message=1#addtag');
41 wp_redirect('edit-tags.php?message=4#addtag');
47 $tag_ID = (int) $_GET['tag_ID'];
48 check_admin_referer('delete-tag_' . $tag_ID);
50 if ( !current_user_can('manage_categories') )
51 wp_die(__('Cheatin’ uh?'));
53 wp_delete_term( $tag_ID, $taxonomy);
55 $location = 'edit-tags.php';
56 if ( $referer = wp_get_referer() ) {
57 if ( false !== strpos($referer, 'edit-tags.php') )
61 $location = add_query_arg('message', 2, $location);
62 wp_redirect($location);
68 check_admin_referer('bulk-tags');
70 if ( !current_user_can('manage_categories') )
71 wp_die(__('Cheatin’ uh?'));
73 $tags = $_GET['delete_tags'];
74 foreach( (array) $tags as $tag_ID ) {
75 wp_delete_term( $tag_ID, $taxonomy);
78 $location = 'edit-tags.php';
79 if ( $referer = wp_get_referer() ) {
80 if ( false !== strpos($referer, 'edit-tags.php') )
84 $location = add_query_arg('message', 6, $location);
85 wp_redirect($location);
91 $title = __('Edit Tag');
93 require_once ('admin-header.php');
94 $tag_ID = (int) $_GET['tag_ID'];
96 $tag = get_term($tag_ID, $taxonomy, OBJECT, 'edit');
97 include('edit-tag-form.php');
102 $tag_ID = (int) $_POST['tag_ID'];
103 check_admin_referer('update-tag_' . $tag_ID);
105 if ( !current_user_can('manage_categories') )
106 wp_die(__('Cheatin’ uh?'));
108 $ret = wp_update_term($tag_ID, $taxonomy, $_POST);
110 $location = 'edit-tags.php';
111 if ( $referer = wp_get_original_referer() ) {
112 if ( false !== strpos($referer, 'edit-tags.php') )
113 $location = $referer;
116 if ( $ret && !is_wp_error( $ret ) )
117 $location = add_query_arg('message', 3, $location);
119 $location = add_query_arg('message', 5, $location);
121 wp_redirect($location);
127 if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
128 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
132 $can_manage = current_user_can('manage_categories');
134 wp_enqueue_script('admin-tags');
136 wp_enqueue_script('inline-edit-tax');
138 require_once ('admin-header.php');
140 $messages[1] = __('Tag added.');
141 $messages[2] = __('Tag deleted.');
142 $messages[3] = __('Tag updated.');
143 $messages[4] = __('Tag not added.');
144 $messages[5] = __('Tag not updated.');
145 $messages[6] = __('Tags deleted.'); ?>
147 <div class="wrap nosubsub">
148 <?php screen_icon(); ?>
149 <h2><?php echo esc_html( $title );
150 if ( isset($_GET['s']) && $_GET['s'] )
151 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
154 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
155 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
156 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
159 <form class="search-form" action="" method="get">
160 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
161 <p class="search-box">
162 <label class="screen-reader-text" for="tag-search-input"><?php _e( 'Search Tags' ); ?>:</label>
163 <input type="text" id="tag-search-input" name="s" value="<?php _admin_search_query(); ?>" />
164 <input type="submit" value="<?php esc_attr_e( 'Search Tags' ); ?>" class="button" />
169 <div id="col-container">
172 <div class="col-wrap">
173 <form id="posts-filter" action="" method="get">
174 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
175 <div class="tablenav">
177 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
178 if ( empty($pagenum) )
181 $tags_per_page = get_user_option('edit_tags_per_page');
182 if ( empty($tags_per_page) )
184 $tags_per_page = apply_filters('edit_tags_per_page', $tags_per_page);
185 $tags_per_page = apply_filters('tagsperpage', $tags_per_page); // Old filter
187 $page_links = paginate_links( array(
188 'base' => add_query_arg( 'pagenum', '%#%' ),
190 'prev_text' => __('«'),
191 'next_text' => __('»'),
192 'total' => ceil(wp_count_terms($taxonomy) / $tags_per_page),
193 'current' => $pagenum
197 echo "<div class='tablenav-pages'>$page_links</div>";
200 <div class="alignleft actions">
201 <select name="action">
202 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
203 <option value="delete"><?php _e('Delete'); ?></option>
205 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
206 <?php wp_nonce_field('bulk-tags'); ?>
212 <div class="clear"></div>
214 <table class="widefat tag fixed" cellspacing="0">
217 <?php print_column_headers('edit-tags'); ?>
223 <?php print_column_headers('edit-tags', false); ?>
227 <tbody id="the-list" class="list:tag">
230 $searchterms = isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '';
232 $count = tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy );
237 <div class="tablenav">
240 echo "<div class='tablenav-pages'>$page_links</div>";
243 <div class="alignleft actions">
244 <select name="action2">
245 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
246 <option value="delete"><?php _e('Delete'); ?></option>
248 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
257 </div><!-- /col-right -->
260 <div class="col-wrap">
262 <div class="tagcloud">
263 <h3><?php _e('Popular Tags'); ?></h3>
266 wp_tag_cloud(array('taxonomy' => $taxonomy, 'link' => 'edit'));
268 wp_tag_cloud(array('taxonomy' => $taxonomy));
272 <?php if ( $can_manage ) {
273 do_action('add_tag_form_pre'); ?>
275 <div class="form-wrap">
276 <h3><?php _e('Add a New Tag'); ?></h3>
277 <div id="ajax-response"></div>
278 <form name="addtag" id="addtag" method="post" action="edit-tags.php" class="add:the-list: validate">
279 <input type="hidden" name="action" value="addtag" />
280 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
281 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-tag'); ?>
283 <div class="form-field form-required">
284 <label for="name"><?php _e('Tag name') ?></label>
285 <input name="name" id="name" type="text" value="" size="40" aria-required="true" />
286 <p><?php _e('The name is how the tag appears on your site.'); ?></p>
289 <div class="form-field">
290 <label for="slug"><?php _e('Tag slug') ?></label>
291 <input name="slug" id="slug" type="text" value="" size="40" />
292 <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>
295 <div class="form-field">
296 <label for="description"><?php _e('Description') ?></label>
297 <textarea name="description" id="description" rows="5" cols="40"></textarea>
298 <p><?php _e('The description is not prominent by default, however some themes may show it.'); ?></p>
301 <p class="submit"><input type="submit" class="button" name="submit" value="<?php esc_attr_e('Add Tag'); ?>" /></p>
302 <?php do_action('add_tag_form'); ?>
307 </div><!-- /col-left -->
309 </div><!-- /col-container -->
312 <?php inline_edit_term_row('edit-tags'); ?>
318 include('admin-footer.php');