3 * Edit Tags Administration Screen.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
13 wp_die( __( 'Invalid taxonomy.' ) );
15 $tax = get_taxonomy( $taxnow );
18 wp_die( __( 'Invalid taxonomy.' ) );
20 if ( ! in_array( $tax->name, get_taxonomies( array( 'show_ui' => true ) ) ) ) {
21 wp_die( __( 'Sorry, you are not allowed to manage these items.' ) );
24 if ( ! current_user_can( $tax->cap->manage_terms ) ) {
26 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
27 '<p>' . __( 'Sorry, you are not allowed to manage these items.' ) . '</p>',
33 * $post_type is set when the WP_Terms_List_Table instance is created
35 * @global string $post_type
39 $wp_list_table = _get_list_table('WP_Terms_List_Table');
40 $pagenum = $wp_list_table->get_pagenum();
42 $title = $tax->labels->name;
44 if ( 'post' != $post_type ) {
45 $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type";
46 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
47 } elseif ( 'link_category' == $tax->name ) {
48 $parent_file = 'link-manager.php';
49 $submenu_file = 'edit-tags.php?taxonomy=link_category';
51 $parent_file = 'edit.php';
52 $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
55 add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) );
57 get_current_screen()->set_screen_reader_content( array(
58 'heading_pagination' => $tax->labels->items_list_navigation,
59 'heading_list' => $tax->labels->items_list,
63 $referer = wp_get_referer();
65 switch ( $wp_list_table->current_action() ) {
69 check_admin_referer( 'add-tag', '_wpnonce_add-tag' );
71 if ( ! current_user_can( $tax->cap->edit_terms ) ) {
73 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
74 '<p>' . __( 'Sorry, you are not allowed to add this item.' ) . '</p>',
79 $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
80 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
81 if ( 'post' != $post_type )
82 $location .= '&post_type=' . $post_type;
84 if ( $referer && false !== strpos( $referer, 'edit-tags.php' ) ) {
88 if ( $ret && !is_wp_error( $ret ) )
89 $location = add_query_arg( 'message', 1, $location );
91 $location = add_query_arg( array( 'error' => true, 'message' => 4 ), $location );
96 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
97 if ( 'post' != $post_type )
98 $location .= '&post_type=' . $post_type;
100 if ( $referer && false !== strpos( $referer, 'edit-tags.php' ) ) {
101 $location = $referer;
104 if ( ! isset( $_REQUEST['tag_ID'] ) ) {
108 $tag_ID = (int) $_REQUEST['tag_ID'];
109 check_admin_referer( 'delete-tag_' . $tag_ID );
111 if ( ! current_user_can( $tax->cap->delete_terms ) ) {
113 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
114 '<p>' . __( 'Sorry, you are not allowed to delete this item.' ) . '</p>',
119 wp_delete_term( $tag_ID, $taxonomy );
121 $location = add_query_arg( 'message', 2, $location );
126 check_admin_referer( 'bulk-tags' );
128 if ( ! current_user_can( $tax->cap->delete_terms ) ) {
130 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
131 '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>',
136 $tags = (array) $_REQUEST['delete_tags'];
137 foreach ( $tags as $tag_ID ) {
138 wp_delete_term( $tag_ID, $taxonomy );
141 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
142 if ( 'post' != $post_type )
143 $location .= '&post_type=' . $post_type;
144 if ( $referer && false !== strpos( $referer, 'edit-tags.php' ) ) {
145 $location = $referer;
148 $location = add_query_arg( 'message', 6, $location );
153 if ( ! isset( $_REQUEST['tag_ID'] ) ) {
157 $term_id = (int) $_REQUEST['tag_ID'];
158 $term = get_term( $term_id );
160 if ( ! $term instanceof WP_Term ) {
161 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
164 wp_redirect( esc_url_raw( get_edit_term_link( $term_id, $taxonomy, $post_type ) ) );
168 $tag_ID = (int) $_POST['tag_ID'];
169 check_admin_referer( 'update-tag_' . $tag_ID );
171 if ( ! current_user_can( $tax->cap->edit_terms ) ) {
173 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
174 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
179 $tag = get_term( $tag_ID, $taxonomy );
181 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
183 $ret = wp_update_term( $tag_ID, $taxonomy, $_POST );
185 $location = 'edit-tags.php?taxonomy=' . $taxonomy;
186 if ( 'post' != $post_type )
187 $location .= '&post_type=' . $post_type;
189 if ( $referer && false !== strpos( $referer, 'edit-tags.php' ) ) {
190 $location = $referer;
193 if ( $ret && !is_wp_error( $ret ) )
194 $location = add_query_arg( 'message', 3, $location );
196 $location = add_query_arg( array( 'error' => true, 'message' => 5 ), $location );
200 if ( ! $location && ! empty( $_REQUEST['_wp_http_referer'] ) ) {
201 $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']) );
205 if ( ! empty( $_REQUEST['paged'] ) ) {
206 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
210 * Filters the taxonomy redirect destination URL.
214 * @param string $location The destination URL.
215 * @param object $tax The taxonomy object.
217 wp_redirect( apply_filters( 'redirect_term_location', $location, $tax ) );
221 $wp_list_table->prepare_items();
222 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
224 if ( $pagenum > $total_pages && $total_pages > 0 ) {
225 wp_redirect( add_query_arg( 'paged', $total_pages ) );
229 wp_enqueue_script('admin-tags');
230 if ( current_user_can($tax->cap->edit_terms) )
231 wp_enqueue_script('inline-edit-tax');
233 if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) {
235 if ( 'category' == $taxonomy )
236 $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>';
237 elseif ( 'link_category' == $taxonomy )
238 $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>';
240 $help = '<p>' . __( 'You can assign keywords to your posts using <strong>tags</strong>. Unlike categories, tags have no hierarchy, meaning there’s no relationship from one tag to another.' ) . '</p>';
242 if ( 'link_category' == $taxonomy )
243 $help .= '<p>' . __( 'You can delete Link Categories in the Bulk Action pull-down, but that action does not delete the links within the category. Instead, it moves them to the default Link Category.' ) . '</p>';
245 $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>';
247 get_current_screen()->add_help_tab( array(
249 'title' => __('Overview'),
253 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) {
254 if ( 'category' == $taxonomy )
255 $help = '<p>' . __( 'When adding a new category on this screen, you’ll fill in the following fields:' ) . '</p>';
257 $help = '<p>' . __( 'When adding a new tag on this screen, you’ll fill in the following fields:' ) . '</p>';
260 '<li>' . __( '<strong>Name</strong> — The name is how it appears on your site.' ) . '</li>';
262 if ( ! global_terms_enabled() )
263 $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>';
265 if ( 'category' == $taxonomy )
266 $help .= '<li>' . __( '<strong>Parent</strong> — Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have child categories for Bebop and Big Band. Totally optional. To create a subcategory, just choose another category from the Parent dropdown.' ) . '</li>';
268 $help .= '<li>' . __( '<strong>Description</strong> — The description is not prominent by default; however, some themes may display it.' ) . '</li>' .
270 '<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>';
272 get_current_screen()->add_help_tab( array(
273 'id' => 'adding-terms',
274 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ),
279 $help = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
281 if ( 'category' == $taxonomy )
282 $help .= '<p>' . __( '<a href="https://codex.wordpress.org/Posts_Categories_Screen" target="_blank">Documentation on Categories</a>' ) . '</p>';
283 elseif ( 'link_category' == $taxonomy )
284 $help .= '<p>' . __( '<a href="https://codex.wordpress.org/Links_Link_Categories_Screen" target="_blank">Documentation on Link Categories</a>' ) . '</p>';
286 $help .= '<p>' . __( '<a href="https://codex.wordpress.org/Posts_Tags_Screen" target="_blank">Documentation on Tags</a>' ) . '</p>';
288 $help .= '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
290 get_current_screen()->set_help_sidebar( $help );
295 require_once( ABSPATH . 'wp-admin/admin-header.php' );
297 if ( ! current_user_can( $tax->cap->edit_terms ) ) {
299 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
300 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
305 /** Also used by the Edit Tag form */
306 require_once( ABSPATH . 'wp-admin/includes/edit-tag-messages.php' );
308 $class = ( isset( $_REQUEST['error'] ) ) ? 'error' : 'updated';
310 if ( is_plugin_active( 'wpcat2tag-importer/wpcat2tag-importer.php' ) ) {
311 $import_link = admin_url( 'admin.php?import=wpcat2tag' );
313 $import_link = admin_url( 'import.php' );
318 <div class="wrap nosubsub">
319 <h1><?php echo esc_html( $title );
320 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
321 /* translators: %s: search keywords */
322 printf( '<span class="subtitle">' . __( 'Search results for “%s”' ) . '</span>', esc_html( wp_unslash( $_REQUEST['s'] ) ) );
327 <?php if ( $message ) : ?>
328 <div id="message" class="<?php echo $class; ?> notice is-dismissible"><p><?php echo $message; ?></p></div>
329 <?php $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'error' ), $_SERVER['REQUEST_URI'] );
331 <div id="ajax-response"></div>
333 <form class="search-form wp-clearfix" method="get">
334 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
335 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
337 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
341 <div id="col-container" class="wp-clearfix">
344 <div class="col-wrap">
348 if ( current_user_can($tax->cap->edit_terms) ) {
349 if ( 'category' == $taxonomy ) {
351 * Fires before the Add Category form.
354 * @deprecated 3.0.0 Use {$taxonomy}_pre_add_form instead.
356 * @param object $arg Optional arguments cast to an object.
358 do_action( 'add_category_form_pre', (object) array( 'parent' => 0 ) );
359 } elseif ( 'link_category' == $taxonomy ) {
361 * Fires before the link category form.
364 * @deprecated 3.0.0 Use {$taxonomy}_pre_add_form instead.
366 * @param object $arg Optional arguments cast to an object.
368 do_action( 'add_link_category_form_pre', (object) array( 'parent' => 0 ) );
371 * Fires before the Add Tag form.
374 * @deprecated 3.0.0 Use {$taxonomy}_pre_add_form instead.
376 * @param string $taxonomy The taxonomy slug.
378 do_action( 'add_tag_form_pre', $taxonomy );
382 * Fires before the Add Term form for all taxonomies.
384 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
388 * @param string $taxonomy The taxonomy slug.
390 do_action( "{$taxonomy}_pre_add_form", $taxonomy );
393 <div class="form-wrap">
394 <h2><?php echo $tax->labels->add_new_item; ?></h2>
395 <form id="addtag" method="post" action="edit-tags.php" class="validate"
398 * Fires at the beginning of the Add Tag form.
400 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
404 do_action( "{$taxonomy}_term_new_form_tag" );
406 <input type="hidden" name="action" value="add-tag" />
407 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
408 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
409 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
410 <?php wp_nonce_field('add-tag', '_wpnonce_add-tag'); ?>
412 <div class="form-field form-required term-name-wrap">
413 <label for="tag-name"><?php _ex( 'Name', 'term name' ); ?></label>
414 <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
415 <p><?php _e('The name is how it appears on your site.'); ?></p>
417 <?php if ( ! global_terms_enabled() ) : ?>
418 <div class="form-field term-slug-wrap">
419 <label for="tag-slug"><?php _e( 'Slug' ); ?></label>
420 <input name="slug" id="tag-slug" type="text" value="" size="40" />
421 <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>
423 <?php endif; // global_terms_enabled() ?>
424 <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
425 <div class="form-field term-parent-wrap">
426 <label for="parent"><?php _ex( 'Parent', 'term parent' ); ?></label>
428 $dropdown_args = array(
430 'hide_if_empty' => false,
431 'taxonomy' => $taxonomy,
434 'hierarchical' => true,
435 'show_option_none' => __( 'None' ),
439 * Filters the taxonomy parent drop-down on the Edit Term page.
442 * @since 4.2.0 Added `$context` parameter.
444 * @param array $dropdown_args {
445 * An array of taxonomy parent drop-down arguments.
447 * @type int|bool $hide_empty Whether to hide terms not attached to any posts. Default 0|false.
448 * @type bool $hide_if_empty Whether to hide the drop-down if no terms exist. Default false.
449 * @type string $taxonomy The taxonomy slug.
450 * @type string $name Value of the name attribute to use for the drop-down select element.
452 * @type string $orderby The field to order by. Default 'name'.
453 * @type bool $hierarchical Whether the taxonomy is hierarchical. Default true.
454 * @type string $show_option_none Label to display if there are no terms. Default 'None'.
456 * @param string $taxonomy The taxonomy slug.
457 * @param string $context Filter context. Accepts 'new' or 'edit'.
459 $dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'new' );
461 wp_dropdown_categories( $dropdown_args );
463 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
464 <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>
467 <?php endif; // is_taxonomy_hierarchical() ?>
468 <div class="form-field term-description-wrap">
469 <label for="tag-description"><?php _e( 'Description' ); ?></label>
470 <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
471 <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
475 if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
477 * Fires after the Add Tag form fields for non-hierarchical taxonomies.
481 * @param string $taxonomy The taxonomy slug.
483 do_action( 'add_tag_form_fields', $taxonomy );
487 * Fires after the Add Term form fields.
489 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
493 * @param string $taxonomy The taxonomy slug.
495 do_action( "{$taxonomy}_add_form_fields", $taxonomy );
497 submit_button( $tax->labels->add_new_item );
499 if ( 'category' == $taxonomy ) {
501 * Fires at the end of the Edit Category form.
504 * @deprecated 3.0.0 Use {$taxonomy}_add_form instead.
506 * @param object $arg Optional arguments cast to an object.
508 do_action( 'edit_category_form', (object) array( 'parent' => 0 ) );
509 } elseif ( 'link_category' == $taxonomy ) {
511 * Fires at the end of the Edit Link form.
514 * @deprecated 3.0.0 Use {$taxonomy}_add_form instead.
516 * @param object $arg Optional arguments cast to an object.
518 do_action( 'edit_link_category_form', (object) array( 'parent' => 0 ) );
521 * Fires at the end of the Add Tag form.
524 * @deprecated 3.0.0 Use {$taxonomy}_add_form instead.
526 * @param string $taxonomy The taxonomy slug.
528 do_action( 'add_tag_form', $taxonomy );
532 * Fires at the end of the Add Term form for all taxonomies.
534 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
538 * @param string $taxonomy The taxonomy slug.
540 do_action( "{$taxonomy}_add_form", $taxonomy );
545 if ( ! is_null( $tax->labels->popular_items ) ) {
546 if ( current_user_can( $tax->cap->edit_terms ) ) {
547 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) );
549 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
554 <div class="tagcloud">
555 <h2><?php echo $tax->labels->popular_items; ?></h2>
556 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
565 </div><!-- /col-left -->
568 <div class="col-wrap">
569 <form id="posts-filter" method="post">
570 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ); ?>" />
571 <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" />
573 <?php $wp_list_table->display(); ?>
577 <?php if ( 'category' == $taxonomy ) : ?>
578 <div class="form-wrap edit-term-notes">
581 echo '<strong>' . __( 'Note:' ) . '</strong><br />';
583 /* translators: %s: default category */
584 __( '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 %s.' ),
585 /** This filter is documented in wp-includes/category-template.php */
586 '<strong>' . apply_filters( 'the_category', get_cat_name( get_option( 'default_category') ) ) . '</strong>'
590 <?php if ( current_user_can( 'import' ) ) : ?>
591 <p><?php printf( __( 'Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.' ), esc_url( $import_link ) ) ?></p>
594 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
595 <div class="form-wrap edit-term-notes">
596 <p><?php printf( __( 'Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>.' ), esc_url( $import_link ) ) ;?></p>
601 * Fires after the taxonomy list table.
603 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
607 * @param string $taxonomy The taxonomy name.
609 do_action( "after-{$taxonomy}-table", $taxonomy );
613 </div><!-- /col-right -->
615 </div><!-- /col-container -->
618 <?php if ( ! wp_is_mobile() ) : ?>
619 <script type="text/javascript">
620 try{document.forms.addtag['tag-name'].focus();}catch(e){}
625 $wp_list_table->inline_edit();
627 include( ABSPATH . 'wp-admin/admin-footer.php' );