Changeset 42343 for trunk/src/wp-admin/edit-tags.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-tags.php
r42228 r42343 10 10 require_once( dirname( __FILE__ ) . '/admin.php' ); 11 11 12 if ( ! $taxnow ) 12 if ( ! $taxnow ) { 13 13 wp_die( __( 'Invalid taxonomy.' ) ); 14 } 14 15 15 16 $tax = get_taxonomy( $taxnow ); 16 17 17 if ( ! $tax ) 18 if ( ! $tax ) { 18 19 wp_die( __( 'Invalid taxonomy.' ) ); 20 } 19 21 20 22 if ( ! in_array( $tax->name, get_taxonomies( array( 'show_ui' => true ) ) ) ) { … … 37 39 global $post_type; 38 40 39 $wp_list_table = _get_list_table( 'WP_Terms_List_Table');40 $pagenum = $wp_list_table->get_pagenum();41 $wp_list_table = _get_list_table( 'WP_Terms_List_Table' ); 42 $pagenum = $wp_list_table->get_pagenum(); 41 43 42 44 $title = $tax->labels->name; 43 45 44 46 if ( 'post' != $post_type ) { 45 $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type";47 $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type"; 46 48 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type"; 47 49 } elseif ( 'link_category' == $tax->name ) { 48 $parent_file = 'link-manager.php';50 $parent_file = 'link-manager.php'; 49 51 $submenu_file = 'edit-tags.php?taxonomy=link_category'; 50 52 } else { 51 $parent_file = 'edit.php';53 $parent_file = 'edit.php'; 52 54 $submenu_file = "edit-tags.php?taxonomy=$taxonomy"; 53 55 } 54 56 55 add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) ); 56 57 get_current_screen()->set_screen_reader_content( array( 58 'heading_pagination' => $tax->labels->items_list_navigation, 59 'heading_list' => $tax->labels->items_list, 60 ) ); 57 add_screen_option( 58 'per_page', array( 59 'default' => 20, 60 'option' => 'edit_' . $tax->name . '_per_page', 61 ) 62 ); 63 64 get_current_screen()->set_screen_reader_content( 65 array( 66 'heading_pagination' => $tax->labels->items_list_navigation, 67 'heading_list' => $tax->labels->items_list, 68 ) 69 ); 61 70 62 71 $location = false; 63 $referer = wp_get_referer();72 $referer = wp_get_referer(); 64 73 if ( ! $referer ) { // For POST requests. 65 74 $referer = wp_unslash( $_SERVER['REQUEST_URI'] ); … … 68 77 switch ( $wp_list_table->current_action() ) { 69 78 70 case 'add-tag': 71 check_admin_referer( 'add-tag', '_wpnonce_add-tag' ); 72 73 if ( ! current_user_can( $tax->cap->edit_terms ) ) { 74 wp_die( 75 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 76 '<p>' . __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) . '</p>', 77 403 78 ); 79 } 80 81 $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); 82 if ( $ret && !is_wp_error( $ret ) ) 83 $location = add_query_arg( 'message', 1, $referer ); 84 else 85 $location = add_query_arg( array( 'error' => true, 'message' => 4 ), $referer ); 86 87 break; 88 89 case 'delete': 90 if ( ! isset( $_REQUEST['tag_ID'] ) ) { 79 case 'add-tag': 80 check_admin_referer( 'add-tag', '_wpnonce_add-tag' ); 81 82 if ( ! current_user_can( $tax->cap->edit_terms ) ) { 83 wp_die( 84 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 85 '<p>' . __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) . '</p>', 86 403 87 ); 88 } 89 90 $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); 91 if ( $ret && ! is_wp_error( $ret ) ) { 92 $location = add_query_arg( 'message', 1, $referer ); 93 } else { 94 $location = add_query_arg( 95 array( 96 'error' => true, 97 'message' => 4, 98 ), $referer 99 ); 100 } 101 91 102 break; 92 } 93 94 $tag_ID = (int) $_REQUEST['tag_ID']; 95 check_admin_referer( 'delete-tag_' . $tag_ID ); 96 97 if ( ! current_user_can( 'delete_term', $tag_ID ) ) { 98 wp_die( 99 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 100 '<p>' . __( 'Sorry, you are not allowed to delete this item.' ) . '</p>', 101 403 102 ); 103 } 104 105 wp_delete_term( $tag_ID, $taxonomy ); 106 107 $location = add_query_arg( 'message', 2, $referer ); 108 109 // When deleting a term, prevent the action from redirecting back to a term that no longer exists. 110 $location = remove_query_arg( array( 'tag_ID', 'action' ), $location ); 111 112 break; 113 114 case 'bulk-delete': 115 check_admin_referer( 'bulk-tags' ); 116 117 if ( ! current_user_can( $tax->cap->delete_terms ) ) { 118 wp_die( 119 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 120 '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>', 121 403 122 ); 123 } 124 125 $tags = (array) $_REQUEST['delete_tags']; 126 foreach ( $tags as $tag_ID ) { 103 104 case 'delete': 105 if ( ! isset( $_REQUEST['tag_ID'] ) ) { 106 break; 107 } 108 109 $tag_ID = (int) $_REQUEST['tag_ID']; 110 check_admin_referer( 'delete-tag_' . $tag_ID ); 111 112 if ( ! current_user_can( 'delete_term', $tag_ID ) ) { 113 wp_die( 114 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 115 '<p>' . __( 'Sorry, you are not allowed to delete this item.' ) . '</p>', 116 403 117 ); 118 } 119 127 120 wp_delete_term( $tag_ID, $taxonomy ); 128 } 129 130 $location = add_query_arg( 'message', 6, $referer ); 131 132 break; 133 134 case 'edit': 135 if ( ! isset( $_REQUEST['tag_ID'] ) ) { 121 122 $location = add_query_arg( 'message', 2, $referer ); 123 124 // When deleting a term, prevent the action from redirecting back to a term that no longer exists. 125 $location = remove_query_arg( array( 'tag_ID', 'action' ), $location ); 126 136 127 break; 137 } 138 139 $term_id = (int) $_REQUEST['tag_ID']; 140 $term = get_term( $term_id ); 141 142 if ( ! $term instanceof WP_Term ) { 143 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); 144 } 145 146 wp_redirect( esc_url_raw( get_edit_term_link( $term_id, $taxonomy, $post_type ) ) ); 147 exit; 148 149 case 'editedtag': 150 $tag_ID = (int) $_POST['tag_ID']; 151 check_admin_referer( 'update-tag_' . $tag_ID ); 152 153 if ( ! current_user_can( 'edit_term', $tag_ID ) ) { 154 wp_die( 155 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 156 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', 157 403 158 ); 159 } 160 161 $tag = get_term( $tag_ID, $taxonomy ); 162 if ( ! $tag ) 163 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); 164 165 $ret = wp_update_term( $tag_ID, $taxonomy, $_POST ); 166 167 if ( $ret && ! is_wp_error( $ret ) ) { 168 $location = add_query_arg( 'message', 3, $referer ); 169 } else { 170 $location = add_query_arg( array( 'error' => true, 'message' => 5 ), $referer ); 171 } 172 break; 173 default: 174 if ( ! $wp_list_table->current_action() || ! isset( $_REQUEST['delete_tags'] ) ) { 128 129 case 'bulk-delete': 130 check_admin_referer( 'bulk-tags' ); 131 132 if ( ! current_user_can( $tax->cap->delete_terms ) ) { 133 wp_die( 134 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 135 '<p>' . __( 'Sorry, you are not allowed to delete these items.' ) . '</p>', 136 403 137 ); 138 } 139 140 $tags = (array) $_REQUEST['delete_tags']; 141 foreach ( $tags as $tag_ID ) { 142 wp_delete_term( $tag_ID, $taxonomy ); 143 } 144 145 $location = add_query_arg( 'message', 6, $referer ); 146 175 147 break; 176 } 177 check_admin_referer( 'bulk-tags' ); 178 $tags = (array) $_REQUEST['delete_tags']; 179 /** This action is documented in wp-admin/edit-comments.php */ 180 $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $tags ); 181 break; 148 149 case 'edit': 150 if ( ! isset( $_REQUEST['tag_ID'] ) ) { 151 break; 152 } 153 154 $term_id = (int) $_REQUEST['tag_ID']; 155 $term = get_term( $term_id ); 156 157 if ( ! $term instanceof WP_Term ) { 158 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); 159 } 160 161 wp_redirect( esc_url_raw( get_edit_term_link( $term_id, $taxonomy, $post_type ) ) ); 162 exit; 163 164 case 'editedtag': 165 $tag_ID = (int) $_POST['tag_ID']; 166 check_admin_referer( 'update-tag_' . $tag_ID ); 167 168 if ( ! current_user_can( 'edit_term', $tag_ID ) ) { 169 wp_die( 170 '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . 171 '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', 172 403 173 ); 174 } 175 176 $tag = get_term( $tag_ID, $taxonomy ); 177 if ( ! $tag ) { 178 wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); 179 } 180 181 $ret = wp_update_term( $tag_ID, $taxonomy, $_POST ); 182 183 if ( $ret && ! is_wp_error( $ret ) ) { 184 $location = add_query_arg( 'message', 3, $referer ); 185 } else { 186 $location = add_query_arg( 187 array( 188 'error' => true, 189 'message' => 5, 190 ), $referer 191 ); 192 } 193 break; 194 default: 195 if ( ! $wp_list_table->current_action() || ! isset( $_REQUEST['delete_tags'] ) ) { 196 break; 197 } 198 check_admin_referer( 'bulk-tags' ); 199 $tags = (array) $_REQUEST['delete_tags']; 200 /** This action is documented in wp-admin/edit-comments.php */ 201 $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $tags ); 202 break; 182 203 } 183 204 … … 211 232 } 212 233 213 wp_enqueue_script('admin-tags'); 214 if ( current_user_can($tax->cap->edit_terms) ) 215 wp_enqueue_script('inline-edit-tax'); 216 217 if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) { 218 $help =''; 219 if ( 'category' == $taxonomy ) 220 $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>'; 221 elseif ( 'link_category' == $taxonomy ) 234 wp_enqueue_script( 'admin-tags' ); 235 if ( current_user_can( $tax->cap->edit_terms ) ) { 236 wp_enqueue_script( 'inline-edit-tax' ); 237 } 238 239 if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) { 240 $help = ''; 241 if ( 'category' == $taxonomy ) { 242 $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>'; 243 } elseif ( 'link_category' == $taxonomy ) { 222 244 $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>'; 223 else245 } else { 224 246 $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>'; 225 226 if ( 'link_category' == $taxonomy ) 247 } 248 249 if ( 'link_category' == $taxonomy ) { 227 250 $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>'; 228 else 229 $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>'; 230 231 get_current_screen()->add_help_tab( array( 232 'id' => 'overview', 233 'title' => __('Overview'), 234 'content' => $help, 235 ) ); 251 } else { 252 $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>'; 253 } 254 255 get_current_screen()->add_help_tab( 256 array( 257 'id' => 'overview', 258 'title' => __( 'Overview' ), 259 'content' => $help, 260 ) 261 ); 236 262 237 263 if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) { 238 if ( 'category' == $taxonomy ) 264 if ( 'category' == $taxonomy ) { 239 265 $help = '<p>' . __( 'When adding a new category on this screen, you’ll fill in the following fields:' ) . '</p>'; 240 else266 } else { 241 267 $help = '<p>' . __( 'When adding a new tag on this screen, you’ll fill in the following fields:' ) . '</p>'; 268 } 242 269 243 270 $help .= '<ul>' . 244 271 '<li>' . __( '<strong>Name</strong> — The name is how it appears on your site.' ) . '</li>'; 245 272 246 if ( ! global_terms_enabled() ) 273 if ( ! global_terms_enabled() ) { 247 274 $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>'; 248 249 if ( 'category' == $taxonomy ) 275 } 276 277 if ( 'category' == $taxonomy ) { 250 278 $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>'; 279 } 251 280 252 281 $help .= '<li>' . __( '<strong>Description</strong> — The description is not prominent by default; however, some themes may display it.' ) . '</li>' . … … 254 283 '<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>'; 255 284 256 get_current_screen()->add_help_tab( array( 257 'id' => 'adding-terms', 258 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ), 259 'content' => $help, 260 ) ); 285 get_current_screen()->add_help_tab( 286 array( 287 'id' => 'adding-terms', 288 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ), 289 'content' => $help, 290 ) 291 ); 261 292 } 262 293 263 294 $help = '<p><strong>' . __( 'For more information:' ) . '</strong></p>'; 264 295 265 if ( 'category' == $taxonomy ) 296 if ( 'category' == $taxonomy ) { 266 297 $help .= '<p>' . __( '<a href="https://codex.wordpress.org/Posts_Categories_Screen">Documentation on Categories</a>' ) . '</p>'; 267 elseif ( 'link_category' == $taxonomy )298 } elseif ( 'link_category' == $taxonomy ) { 268 299 $help .= '<p>' . __( '<a href="https://codex.wordpress.org/Links_Link_Categories_Screen">Documentation on Link Categories</a>' ) . '</p>'; 269 else300 } else { 270 301 $help .= '<p>' . __( '<a href="https://codex.wordpress.org/Posts_Tags_Screen">Documentation on Tags</a>' ) . '</p>'; 271 272 $help .= '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'; 302 } 303 304 $help .= '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'; 273 305 274 306 get_current_screen()->set_help_sidebar( $help ); … … 306 338 <?php if ( $message ) : ?> 307 339 <div id="message" class="<?php echo $class; ?> notice is-dismissible"><p><?php echo $message; ?></p></div> 308 <?php $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'error' ), $_SERVER['REQUEST_URI'] ); 309 endif; ?> 340 <?php 341 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'error' ), $_SERVER['REQUEST_URI'] ); 342 endif; 343 ?> 310 344 <div id="ajax-response"></div> 311 345 312 346 <form class="search-form wp-clearfix" method="get"> 313 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy); ?>" />314 <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type); ?>" />347 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ); ?>" /> 348 <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" /> 315 349 316 350 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?> … … 325 359 <?php 326 360 327 if ( current_user_can( $tax->cap->edit_terms) ) {361 if ( current_user_can( $tax->cap->edit_terms ) ) { 328 362 if ( 'category' == $taxonomy ) { 329 363 /** 330 364 * Fires before the Add Category form. 331 365 * 332 366 * @since 2.1.0 … … 372 406 <div class="form-wrap"> 373 407 <h2><?php echo $tax->labels->add_new_item; ?></h2> 374 <form id="addtag" method="post" action="edit-tags.php" class="validate"<?php 408 <form id="addtag" method="post" action="edit-tags.php" class="validate" 409 <?php 375 410 /** 376 411 * Fires inside the Add Tag form tag. … … 381 416 */ 382 417 do_action( "{$taxonomy}_term_new_form_tag" ); 383 ?>> 418 ?> 419 > 384 420 <input type="hidden" name="action" value="add-tag" /> 385 <input type="hidden" name="screen" value="<?php echo esc_attr( $current_screen->id); ?>" />386 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy); ?>" />387 <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type); ?>" />388 <?php wp_nonce_field( 'add-tag', '_wpnonce_add-tag'); ?>421 <input type="hidden" name="screen" value="<?php echo esc_attr( $current_screen->id ); ?>" /> 422 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ); ?>" /> 423 <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" /> 424 <?php wp_nonce_field( 'add-tag', '_wpnonce_add-tag' ); ?> 389 425 390 426 <div class="form-field form-required term-name-wrap"> 391 427 <label for="tag-name"><?php _ex( 'Name', 'term name' ); ?></label> 392 428 <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" /> 393 <p><?php _e( 'The name is how it appears on your site.'); ?></p>429 <p><?php _e( 'The name is how it appears on your site.' ); ?></p> 394 430 </div> 395 431 <?php if ( ! global_terms_enabled() ) : ?> … … 397 433 <label for="tag-slug"><?php _e( 'Slug' ); ?></label> 398 434 <input name="slug" id="tag-slug" type="text" value="" size="40" /> 399 <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>435 <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> 400 436 </div> 401 437 <?php endif; // global_terms_enabled() ?> 402 <?php if ( is_taxonomy_hierarchical( $taxonomy) ) : ?>438 <?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : ?> 403 439 <div class="form-field term-parent-wrap"> 404 440 <label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label> … … 449 485 <label for="tag-description"><?php _e( 'Description' ); ?></label> 450 486 <textarea name="description" id="tag-description" rows="5" cols="40"></textarea> 451 <p><?php _e( 'The description is not prominent by default; however, some themes may show it.'); ?></p>487 <p><?php _e( 'The description is not prominent by default; however, some themes may show it.' ); ?></p> 452 488 </div> 453 489 … … 548 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.' ), 549 585 /** This filter is documented in wp-includes/category-template.php */ 550 '<strong>' . apply_filters( 'the_category', get_cat_name( get_option( 'default_category' ) ), '', '' ) . '</strong>'586 '<strong>' . apply_filters( 'the_category', get_cat_name( get_option( 'default_category' ) ), '', '' ) . '</strong>' 551 587 ); 552 588 ?> 553 589 </p> 554 590 <?php if ( current_user_can( 'import' ) ) : ?> 555 <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>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> 556 592 <?php endif; ?> 557 593 </div> 558 594 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?> 559 595 <div class="form-wrap edit-term-notes"> 560 <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> 561 </div> 562 <?php endif; 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> 597 </div> 598 <?php 599 endif; 563 600 564 601 /**
Note: See TracChangeset
for help on using the changeset viewer.