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['tag-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 if ( !isset( $_GET['tag_ID'] ) ) {
48 wp_redirect("edit-tags.php?taxonomy=$taxonomy");
52 $tag_ID = (int) $_GET['tag_ID'];
53 check_admin_referer('delete-tag_' . $tag_ID);
55 if ( !current_user_can('manage_categories') )
56 wp_die(__('Cheatin’ uh?'));
58 wp_delete_term( $tag_ID, $taxonomy);
60 $location = 'edit-tags.php';
61 if ( $referer = wp_get_referer() ) {
62 if ( false !== strpos($referer, 'edit-tags.php') )
66 $location = add_query_arg('message', 2, $location);
67 wp_redirect($location);
73 check_admin_referer('bulk-tags');
75 if ( !current_user_can('manage_categories') )
76 wp_die(__('Cheatin’ uh?'));
78 $tags = (array) $_GET['delete_tags'];
79 foreach( $tags as $tag_ID ) {
80 wp_delete_term( $tag_ID, $taxonomy);
83 $location = 'edit-tags.php';
84 if ( $referer = wp_get_referer() ) {
85 if ( false !== strpos($referer, 'edit-tags.php') )
89 $location = add_query_arg('message', 6, $location);
90 wp_redirect($location);
96 $title = __('Edit Tag');
98 require_once ('admin-header.php');
99 $tag_ID = (int) $_GET['tag_ID'];
101 $tag = get_term($tag_ID, $taxonomy, OBJECT, 'edit');
102 include('edit-tag-form.php');
107 $tag_ID = (int) $_POST['tag_ID'];
108 check_admin_referer('update-tag_' . $tag_ID);
110 if ( !current_user_can('manage_categories') )
111 wp_die(__('Cheatin’ uh?'));
113 $ret = wp_update_term($tag_ID, $taxonomy, $_POST);
115 $location = 'edit-tags.php';
116 if ( $referer = wp_get_original_referer() ) {
117 if ( false !== strpos($referer, 'edit-tags.php') )
118 $location = $referer;
121 if ( $ret && !is_wp_error( $ret ) )
122 $location = add_query_arg('message', 3, $location);
124 $location = add_query_arg('message', 5, $location);
126 wp_redirect($location);
132 if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
133 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
137 $can_manage = current_user_can('manage_categories');
139 wp_enqueue_script('admin-tags');
141 wp_enqueue_script('inline-edit-tax');
143 require_once ('admin-header.php');
145 $messages[1] = __('Tag added.');
146 $messages[2] = __('Tag deleted.');
147 $messages[3] = __('Tag updated.');
148 $messages[4] = __('Tag not added.');
149 $messages[5] = __('Tag not updated.');
150 $messages[6] = __('Tags deleted.'); ?>
152 <div class="wrap nosubsub">
153 <?php screen_icon(); ?>
154 <h2><?php echo esc_html( $title );
155 if ( isset($_GET['s']) && $_GET['s'] )
156 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
159 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
160 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
161 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
163 <div id="ajax-response"></div>
165 <form class="search-form" action="" method="get">
166 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
167 <p class="search-box">
168 <label class="screen-reader-text" for="tag-search-input"><?php _e( 'Search Tags' ); ?>:</label>
169 <input type="text" id="tag-search-input" name="s" value="<?php _admin_search_query(); ?>" />
170 <input type="submit" value="<?php esc_attr_e( 'Search Tags' ); ?>" class="button" />
175 <div id="col-container">
178 <div class="col-wrap">
179 <form id="posts-filter" action="" method="get">
180 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
181 <div class="tablenav">
183 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
184 if ( empty($pagenum) )
187 $tags_per_page = (int) get_user_option( 'edit_tags_per_page', 0, false );
188 if ( empty($tags_per_page) || $tags_per_page < 1 )
190 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
191 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
193 $page_links = paginate_links( array(
194 'base' => add_query_arg( 'pagenum', '%#%' ),
196 'prev_text' => __('«'),
197 'next_text' => __('»'),
198 'total' => ceil(wp_count_terms($taxonomy) / $tags_per_page),
199 'current' => $pagenum
203 echo "<div class='tablenav-pages'>$page_links</div>";
206 <div class="alignleft actions">
207 <select name="action">
208 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
209 <option value="delete"><?php _e('Delete'); ?></option>
211 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
212 <?php wp_nonce_field('bulk-tags'); ?>
218 <div class="clear"></div>
220 <table class="widefat tag fixed" cellspacing="0">
223 <?php print_column_headers('edit-tags'); ?>
229 <?php print_column_headers('edit-tags', false); ?>
233 <tbody id="the-list" class="list:tag">
236 $searchterms = isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '';
238 $count = tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy );
243 <div class="tablenav">
246 echo "<div class='tablenav-pages'>$page_links</div>";
249 <div class="alignleft actions">
250 <select name="action2">
251 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
252 <option value="delete"><?php _e('Delete'); ?></option>
254 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
263 </div><!-- /col-right -->
266 <div class="col-wrap">
268 <div class="tagcloud">
269 <h3><?php _e('Popular Tags'); ?></h3>
272 wp_tag_cloud(array('taxonomy' => $taxonomy, 'link' => 'edit'));
274 wp_tag_cloud(array('taxonomy' => $taxonomy));
278 <?php if ( $can_manage ) {
279 do_action('add_tag_form_pre'); ?>
281 <div class="form-wrap">
282 <h3><?php _e('Add a New Tag'); ?></h3>
283 <form id="addtag" method="post" action="edit-tags.php" class="validate">
284 <input type="hidden" name="action" value="add-tag" />
285 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
286 <?php wp_nonce_field('add-tag'); ?>
288 <div class="form-field form-required">
289 <label for="tag-name"><?php _e('Tag name') ?></label>
290 <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
291 <p><?php _e('The name is how the tag appears on your site.'); ?></p>
294 <div class="form-field">
295 <label for="slug"><?php _e('Tag slug') ?></label>
296 <input name="slug" id="slug" type="text" value="" size="40" />
297 <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>
300 <div class="form-field">
301 <label for="description"><?php _e('Description') ?></label>
302 <textarea name="description" id="description" rows="5" cols="40"></textarea>
303 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
306 <p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php esc_attr_e('Add Tag'); ?>" /></p>
307 <?php do_action('add_tag_form'); ?>
312 </div><!-- /col-left -->
314 </div><!-- /col-container -->
317 <?php inline_edit_term_row('edit-tags'); ?>
323 include('admin-footer.php');