From 8b641ea58d89daf1b38e5fe0ffce0a7ded04603d Mon Sep 17 00:00:00 2001 From: Vishal Singh Date: Thu, 9 Apr 2026 15:07:56 +0530 Subject: [PATCH] Reusable admin CSS for destructive actions --- src/wp-admin/css/colors/_admin.scss | 7 +++++-- src/wp-admin/css/common.css | 11 +++++++++++ src/wp-admin/edit-form-comment.php | 2 +- src/wp-admin/edit-tag-form.php | 2 +- src/wp-admin/includes/class-walker-nav-menu-edit.php | 2 +- .../includes/class-wp-comments-list-table.php | 4 ++-- src/wp-admin/includes/class-wp-links-list-table.php | 2 +- src/wp-admin/includes/class-wp-media-list-table.php | 6 +++--- src/wp-admin/includes/class-wp-posts-list-table.php | 4 ++-- src/wp-admin/includes/class-wp-terms-list-table.php | 2 +- src/wp-admin/includes/class-wp-themes-list-table.php | 2 +- src/wp-admin/includes/class-wp-users-list-table.php | 4 ++-- src/wp-admin/includes/meta-boxes.php | 8 ++++---- src/wp-admin/includes/post.php | 2 +- src/wp-admin/nav-menus.php | 2 +- 15 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/wp-admin/css/colors/_admin.scss b/src/wp-admin/css/colors/_admin.scss index 271cefcd854d0..67f5f6fca7bf1 100644 --- a/src/wp-admin/css/colors/_admin.scss +++ b/src/wp-admin/css/colors/_admin.scss @@ -65,7 +65,8 @@ span.wp-media-buttons-icon:before { .media-modal .delete-attachment, .media-modal .trash-attachment, .media-modal .untrash-attachment, -.wp-core-ui .button-link-delete { +.wp-core-ui .button-link-delete, +.wp-core-ui .delete-link { color: tokens.$alert-red; } @@ -76,7 +77,9 @@ span.wp-media-buttons-icon:before { .media-modal .trash-attachment:focus, .media-modal .untrash-attachment:focus, .wp-core-ui .button-link-delete:hover, -.wp-core-ui .button-link-delete:focus { +.wp-core-ui .button-link-delete:focus, +.wp-core-ui .delete-link:hover, +.wp-core-ui .delete-link:focus { color: color.adjust(tokens.$alert-red, $lightness: 10%); } diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index b317af45e023e..1b4ebe84b042b 100644 --- a/src/wp-admin/css/common.css +++ b/src/wp-admin/css/common.css @@ -919,6 +919,17 @@ a#remove-post-thumbnail:hover, border: none; } +/* Destructive action link. For use in custom plugin/theme admin pages. */ +.delete-link { + color: #b32d2e; +} + +.delete-link:hover, +.delete-link:focus { + color: #b32d2e; + border: none; +} + .application-password-display .success { color: #007017; margin-left: 0.5rem; diff --git a/src/wp-admin/edit-form-comment.php b/src/wp-admin/edit-form-comment.php index e0bbc9f657a73..9eb29dc98e230 100644 --- a/src/wp-admin/edit-form-comment.php +++ b/src/wp-admin/edit-form-comment.php @@ -239,7 +239,7 @@
-comment_ID&_wp_original_http_referer=" . urlencode( wp_get_referer() ), 'delete-comment_' . $comment->comment_ID ) . "'>" . ( ! EMPTY_TRASH_DAYS ? __( 'Delete Permanently' ) : __( 'Move to Trash' ) ) . "\n"; ?> +comment_ID&_wp_original_http_referer=" . urlencode( wp_get_referer() ), 'delete-comment_' . $comment->comment_ID ) . "'>" . ( ! EMPTY_TRASH_DAYS ? __( 'Delete Permanently' ) : __( 'Move to Trash' ) ) . "\n"; ?>
diff --git a/src/wp-admin/edit-tag-form.php b/src/wp-admin/edit-tag-form.php index 4373c0a67f8b3..f00235c2e4623 100644 --- a/src/wp-admin/edit-tag-form.php +++ b/src/wp-admin/edit-tag-form.php @@ -302,7 +302,7 @@ term_id ) ) : ?> - term_id", 'delete-tag_' . $tag->term_id ) ) ); ?>"> + term_id", 'delete-tag_' . $tag->term_id ) ) ); ?>"> diff --git a/src/wp-admin/includes/class-walker-nav-menu-edit.php b/src/wp-admin/includes/class-walker-nav-menu-edit.php index a287a7c4b8cdd..bd875ee54db77 100644 --- a/src/wp-admin/includes/class-walker-nav-menu-edit.php +++ b/src/wp-admin/includes/class-walker-nav-menu-edit.php @@ -301,7 +301,7 @@ public function start_el( &$output, $data_object, $depth = 0, $args = null, $cur %s', + '%s', $item_id, wp_nonce_url( add_query_arg( diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php index 1feaeb3283bcd..c8ffe0f0d9614 100644 --- a/src/wp-admin/includes/class-wp-comments-list-table.php +++ b/src/wp-admin/includes/class-wp-comments-list-table.php @@ -832,7 +832,7 @@ protected function handle_row_actions( $item, $column_name, $primary ) { if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) { $actions['delete'] = sprintf( - '%s', + '%s', esc_url( $delete_url ), "delete:the-comment-list:comment-{$comment->comment_ID}::delete=1", esc_attr__( 'Delete this comment permanently' ), @@ -840,7 +840,7 @@ protected function handle_row_actions( $item, $column_name, $primary ) { ); } else { $actions['trash'] = sprintf( - '%s', + '%s', esc_url( $trash_url ), "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1", esc_attr__( 'Move this comment to the Trash' ), diff --git a/src/wp-admin/includes/class-wp-links-list-table.php b/src/wp-admin/includes/class-wp-links-list-table.php index 309a00801adba..038753ee337aa 100644 --- a/src/wp-admin/includes/class-wp-links-list-table.php +++ b/src/wp-admin/includes/class-wp-links-list-table.php @@ -355,7 +355,7 @@ protected function handle_row_actions( $item, $column_name, $primary ) { $actions = array(); $actions['edit'] = '' . __( 'Edit' ) . ''; $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ), /* translators: %s: Link name. */ esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 9476d23c4904d..f2c40f199cc1c 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -815,7 +815,7 @@ private function _get_row_actions( $post, $att_title ) { if ( current_user_can( 'delete_post', $post->ID ) ) { if ( $this->is_trash ) { $actions['untrash'] = sprintf( - '%s', + '%s', esc_url( wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ) ), /* translators: %s: Attachment title. */ esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $att_title ) ), @@ -823,7 +823,7 @@ private function _get_row_actions( $post, $att_title ) { ); } elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { $actions['trash'] = sprintf( - '%s', + '%s', esc_url( wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ) ), /* translators: %s: Attachment title. */ esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ), @@ -835,7 +835,7 @@ private function _get_row_actions( $post, $att_title ) { $show_confirmation = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; $actions['delete'] = sprintf( - '%s', + '%s', esc_url( wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ) ), $show_confirmation, /* translators: %s: Attachment title. */ diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index c7d10fca217ef..b6b424ab096a1 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -1561,7 +1561,7 @@ protected function handle_row_actions( $item, $column_name, $primary ) { ); } elseif ( EMPTY_TRASH_DAYS ) { $actions['trash'] = sprintf( - '%s', + '%s', get_delete_post_link( $post->ID ), /* translators: %s: Post title. */ esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $title ) ), @@ -1571,7 +1571,7 @@ protected function handle_row_actions( $item, $column_name, $primary ) { if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) { $actions['delete'] = sprintf( - '%s', + '%s', get_delete_post_link( $post->ID, '', true ), /* translators: %s: Post title. */ esc_attr( sprintf( __( 'Delete “%s” permanently' ), $title ) ), diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index 75e37e45d5c4f..5202f9ec91048 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -512,7 +512,7 @@ protected function handle_row_actions( $item, $column_name, $primary ) { if ( current_user_can( 'delete_term', $tag->term_id ) ) { $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ), /* translators: %s: Taxonomy term name. */ esc_attr( sprintf( __( 'Delete “%s”' ), $tag->name ) ), diff --git a/src/wp-admin/includes/class-wp-themes-list-table.php b/src/wp-admin/includes/class-wp-themes-list-table.php index 0e9a0fe8b9f2d..f782efa2b4533 100644 --- a/src/wp-admin/includes/class-wp-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-themes-list-table.php @@ -228,7 +228,7 @@ public function display_rows() { if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) { $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ), /* translators: %s: Theme name. */ esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ), diff --git a/src/wp-admin/includes/class-wp-users-list-table.php b/src/wp-admin/includes/class-wp-users-list-table.php index 9a8709b438e05..3fa1632cc544f 100644 --- a/src/wp-admin/includes/class-wp-users-list-table.php +++ b/src/wp-admin/includes/class-wp-users-list-table.php @@ -478,13 +478,13 @@ public function single_row( $user_object, $style = '', $role = '', $numposts = 0 && get_current_user_id() !== $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) { - $actions['delete'] = "" . __( 'Delete' ) . ''; + $actions['delete'] = "" . __( 'Delete' ) . ''; } if ( is_multisite() && current_user_can( 'remove_user', $user_object->ID ) ) { - $actions['remove'] = "" . __( 'Remove' ) . ''; + $actions['remove'] = "" . __( 'Remove' ) . ''; } // Add a link to the user's author archive, if not empty. diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php index 0884c110b65bd..908e60462ea95 100644 --- a/src/wp-admin/includes/meta-boxes.php +++ b/src/wp-admin/includes/meta-boxes.php @@ -367,7 +367,7 @@ function post_submit_meta_box( $post, $args = array() ) { $delete_text = __( 'Move to Trash' ); } ?> - + @@ -469,7 +469,7 @@ function attachment_submit_meta_box( $post ) { if ( current_user_can( 'delete_post', $post->ID ) ) { if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { printf( - '%2$s', + '%2$s', get_delete_post_link( $post->ID ), __( 'Move to Trash' ) ); @@ -477,7 +477,7 @@ function attachment_submit_meta_box( $post ) { $show_confirmation = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; printf( - '%3$s', + '%3$s', $show_confirmation, get_delete_post_link( $post->ID, '', true ), __( 'Delete permanently' ) @@ -1134,7 +1134,7 @@ function link_submit_meta_box( $link ) { %s', + '%s', wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ), /* translators: %s: Link name. */ esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 8d52c1487a7a5..1356975032fa1 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1683,7 +1683,7 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { $thumbnail_html ); $content .= '

' . __( 'Click the image to edit or update' ) . '

'; - $content .= '

' . esc_html( $post_type_object->labels->remove_featured_image ) . '

'; + $content .= '

' . esc_html( $post_type_object->labels->remove_featured_image ) . '

'; } } diff --git a/src/wp-admin/nav-menus.php b/src/wp-admin/nav-menus.php index 808574f1250d6..7904b7b1787b8 100644 --- a/src/wp-admin/nav-menus.php +++ b/src/wp-admin/nav-menus.php @@ -1269,7 +1269,7 @@ function wp_nav_menu_max_depth( $classes ) { %2$s', + '%2$s', esc_url( wp_nonce_url( add_query_arg(