From c21b828581d0a6ee69d2fcf804ff470d2944e1a1 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 12 May 2017 19:25:43 +0000 Subject: [PATCH] Taxonomy: Add a "delete" button on term edit page. Add a 'delete' link next to the update button on the term edit screen so you can delete a term while you are reviewing it's details. Props cklosows, bradt, ocean90, johnbillion, DrewAPicture, ryan, MatheusGimenez, maguiar. Fixes #9777. git-svn-id: https://develop.svn.wordpress.org/trunk@40655 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/common.css | 17 +++++++++++++++-- src/wp-admin/css/edit.css | 15 +++++++++++++++ src/wp-admin/edit-tag-form.php | 15 +++++++++++++-- src/wp-admin/edit-tags.php | 4 +++- src/wp-admin/js/tags.js | 11 +++++++++++ src/wp-admin/term.php | 2 +- 6 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index c4a2e68f88..c769898281 100644 --- a/src/wp-admin/css/common.css +++ b/src/wp-admin/css/common.css @@ -874,7 +874,8 @@ hr { .submitbox .submitdelete, #media-items a.delete, #media-items a.delete-permanently, -#nav-menu-footer .menu-delete { +#nav-menu-footer .menu-delete, +#delete-link a.delete { color: #a00; } @@ -890,7 +891,8 @@ span.required, .submitbox .submitdelete:hover, #media-items a.delete:hover, #media-items a.delete-permanently:hover, -#nav-menu-footer .menu-delete:hover { +#nav-menu-footer .menu-delete:hover, +#delete-link a.delete:hover { color: #dc3232; border: none; } @@ -911,6 +913,17 @@ span.required, line-height: 28px; } +#delete-link { + line-height: 28px; + vertical-align: middle; + text-align: left; + margin-left: 8px; +} + +#delete-link a { + text-decoration: none; +} + #publishing-action { text-align: right; float: right; diff --git a/src/wp-admin/css/edit.css b/src/wp-admin/css/edit.css index 92a8a896fa..03ace83e6a 100644 --- a/src/wp-admin/css/edit.css +++ b/src/wp-admin/css/edit.css @@ -1092,6 +1092,17 @@ p.popular-tags a { text-decoration: underline; } +#edittag { + max-width: 800px; +} + +.edit-tag-actions { + margin-top: 20px; + overflow: hidden; + padding: 10px; + margin-right: 10px; +} + /* Comments */ .comment-php .wp-editor-area { @@ -1348,6 +1359,10 @@ table.links-table { } @media screen and ( max-width: 782px ) { + .wp-core-ui .edit-tag-actions .button-primary { + margin-bottom: 0; + } + #post-body-content { min-width: 0; } diff --git a/src/wp-admin/edit-tag-form.php b/src/wp-admin/edit-tag-form.php index d676f73a09..e2fe71b1cd 100644 --- a/src/wp-admin/edit-tag-form.php +++ b/src/wp-admin/edit-tag-form.php @@ -254,9 +254,20 @@ if ( 'category' == $taxonomy ) { * @param string $taxonomy Current taxonomy slug. */ do_action( "{$taxonomy}_edit_form", $tag, $taxonomy ); - -submit_button( __('Update') ); ?> + +
+ + + + term_id ) ) : ?> + + term_id", 'delete-tag_' . $tag->term_id ) ) ?>"'> + + + +
+ diff --git a/src/wp-admin/edit-tags.php b/src/wp-admin/edit-tags.php index d34c70811b..b575a838d9 100644 --- a/src/wp-admin/edit-tags.php +++ b/src/wp-admin/edit-tags.php @@ -65,7 +65,6 @@ if ( ! $referer ) { // For POST requests. $referer = wp_unslash( $_SERVER['REQUEST_URI'] ); } $referer = remove_query_arg( array( '_wp_http_referer', '_wpnonce', 'error', 'message', 'paged' ), $referer ); - switch ( $wp_list_table->current_action() ) { case 'add-tag': @@ -107,6 +106,9 @@ case 'delete': $location = add_query_arg( 'message', 2, $referer ); + // When deleting a term, prevent the action from redirecting back to a term that no longer exists. + $location = remove_query_arg( array( 'tag_ID', 'action' ), $location ); + break; case 'bulk-delete': diff --git a/src/wp-admin/js/tags.js b/src/wp-admin/js/tags.js index 333a2eb563..fc923f1f8d 100644 --- a/src/wp-admin/js/tags.js +++ b/src/wp-admin/js/tags.js @@ -28,6 +28,17 @@ jQuery(document).ready(function($) { return false; }); + $( '#edittag' ).on( 'click', '.delete', function( e ) { + if ( 'undefined' === typeof showNotice ) { + return true; + } + + var response = showNotice.warn(); + if ( ! response ) { + e.preventDefault(); + } + }); + $('#submit').click(function(){ var form = $(this).parents('form'); diff --git a/src/wp-admin/term.php b/src/wp-admin/term.php index 2018ac0415..1f79f088e0 100644 --- a/src/wp-admin/term.php +++ b/src/wp-admin/term.php @@ -62,7 +62,7 @@ get_current_screen()->set_screen_reader_content( array( 'heading_pagination' => $tax->labels->items_list_navigation, 'heading_list' => $tax->labels->items_list, ) ); - +wp_enqueue_script( 'admin-tags' ); require_once( ABSPATH . 'wp-admin/admin-header.php' ); include( ABSPATH . 'wp-admin/edit-tag-form.php' ); include( ABSPATH . 'wp-admin/admin-footer.php' );