#36882 closed enhancement (fixed)
Add a reusable admin CSS class for destructive actions
| Reported by: | flixos90 | Owned by: | joedolson |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Administration | Version: | |
| Severity: | normal | Keywords: | has-patch dev-feedback needs-dev-note add-to-field-guide |
| Cc: | Focuses: |
Description
As generally recommended, plugin authors should not use regular buttons for destructive actions, like removing something.
However, while there are standardized classes for buttons in WordPress admin (button, button-primary, button-secondary), a similar standardized class is missing for the destructive link. There are several locations in the admin where such links are displayed, but these are all styled using their individual selectors. Therefore plugin authors who want to use this style must either use one of these selectors (that probably do not fit the use-case at all) or recreate the style manually. Therefore I propose to standardize these style rules for a specific class, for example something like delete-button or delete-link.
Change History (35)
#3
@
10 years ago
Thinking at #35126 where a specific class .button-link-delete was added for this purpose, it just makes sense to me to do the same thing for links too.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
#7
@
10 years ago
- Milestone 4.8 → 4.8.1
Per yesterday's bug scrub, we're going to punt this to 4.8.1.
#8
@
10 years ago
Worth noting [40052] introduced .button-link-delete for <button> elements that look like links. Something similar could be done for the links.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
9 years ago
#11
@
9 years ago
- Milestone 4.8.1 → 4.9
Per today's bug scrub, we'll punt this as the focus for 4.8.1 is regressions only.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
9 years ago
#13
@
9 years ago
- Milestone 4.9 → Future Release
Punting to Future Release per today's 4.9 bug scrub.
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
8 months ago
#16
@
8 months ago
- Milestone Future Release → 7.1
I'm going to milestone this for 7.1, as a follow-up to the 7.0 admin reskin.
This ticket was mentioned in PR #12449 on WordPress/wordpress-develop by @sukhendu2002.
4 months ago
#17
- Keywords has-patch has-unit-tests added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/36882
#19
@
4 months ago
We cannot change the milestone due to an issue with Trac itself, but since 7.1 Beta1 is imminent, I would like to mark this ticket to be punted to 7.2 at least. The linked PR has not been reviewed at all yet.
#20
@
4 months ago
I agree with punting to 7.2. The PR is in good shape, and if I'd known it was there I'd have happily reviewed it sooner; but there isn't time at this point.
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
4 months ago
This ticket was mentioned in PR #12580 on WordPress/wordpress-develop by @khokansardar.
4 months ago
#23
- Keywords has-patch added; needs-patch removed
Adds a reusable .delete-link admin CSS class so plugin and theme authors have a standard class for destructive action links, mirroring the existing .button-link-delete class used for destructive <button> elements.
What the problem was:
- The admin standardizes destructive
<button>styling via.button-link-delete(added in [40052] / #35126), but there is no equivalent class for destructive<a>links. - Authors wanting that style had to reuse core selectors that don't fit their use case, or recreate the red color rules by hand.
What the fix does:
- Adds
.delete-linkalongside.button-link-deletein the admin color scheme (_admin.scss), for both the base color and the hover/focus color.
Approach and why:
- The admin
<body>carries thewp-core-uiclass and every admin page loads a compiled color scheme, so.wp-core-ui .delete-linkis available on any admin page, including custom plugin/theme screens — no separatecommon.cssrule is needed. - Color-only rule (no base styling): unlike
.button-link-delete, which needs.button-linkto make a<button>look like a link, an<a>already looks like a link, so only the destructive color is required. - Scheme-aware by construction: it reuses the same
$alert-redtoken and lightened hover/focus, so it stays consistent across all color schemes.
Trac ticket: https://core.trac.wordpress.org/ticket/36882
## Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Ticket analysis and verification. All changes were reviewed, validated against the codebase, and are taken responsibility for by me.
#24
@
4 months ago
PR 11519 takes the right approach — the core .delete-link addition there matches what afercia proposed in comment:3 and comment:8 (mirroring .button-link-delete from #35126 / [40052]).
I've pushed a more minimal alternative for consideration: https://github.com/WordPress/wordpress-develop/pull/12580
It keeps only the essential piece — adding .delete-link next to .button-link-delete in the color scheme (wp-admin/css/colors/_admin.scss), for both the base and the :hover/:focus color. That single ~3-line change gives plugin and theme authors the reusable, scheme-aware class the ticket asks for.
#25
@
4 months ago
What this doesn't add is a class for buttons that are *not* styled as links but are intended for destructive actions. This covers link styling, but not button styling.
An example is the 'Delete Permanently' in the media grid bulk actions, which is a destructive button styled as a primary button.
Can you look at addressing a button style for destructive actions, too?
This ticket was mentioned in PR #13265 on WordPress/wordpress-develop by @logicrays.
3 months ago
#26
## Summary
- Adds a reusable
.delete-linkadmin CSS class for destructive action links. - Mirrors the existing
.button-link-deletecolor rules (base + hover/focus) in the admin color schemes. - Gives plugin and theme authors a standard class instead of reusing unrelated core selectors or copying red link styles by hand.
## Test plan
- [ ] Confirm
.wp-core-ui .delete-linkuses the alert-red color in an admin screen - [ ] Confirm hover/focus lightens/darkens consistently with
.button-link-delete - [ ] Confirm existing
.button-link-deletebuttons are unchanged - [ ] Spot-check at least one admin color scheme (e.g. Default / Modern)
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
6 weeks ago
#28
@
6 weeks ago
- Keywords needs-testing dev-feedback added
As per today's 7.2 bug scrub:
We have a PR ready for testing, so I'm adding needs-testing and dev-feedback.
#29
@
5 weeks ago
- Keywords needs-testing removed
Patch Testing Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/13265 (head dcdcb0b)
Environment
- WordPress: trunk (7.2-alpha-63166-src,
4b2b478948) - PHP: 8.2.29 (php-fpm)
- Server: nginx 1.31.6
- Database: MySQL 8.4.8
- Browser: Chromium 151 (headless, Playwright) for the scripted checks, plus a manual check in the browser;
SCRIPT_DEBUGon - OS: Windows (WSL2, Docker)
- Theme: Twenty Twenty-Five
- MU Plugins:
- fix-docker-loopback (local env helper)
- test-trac-36882.php (test fixture: adds a Tools > Trac 36882 page, see Support Content)
- Plugins: none activated
Steps taken
Reproduction on clean trunk
- Added a test admin page with a plain link, a link using the proposed
.delete-linkclass, and a<button class="button-link button-link-delete">for comparison. - Rebuilt the color schemes (
npm run grunt -- colors --dev). For all nine admin color schemes (Default/modern, Fresh, Light, Blue, Midnight, Sunrise, Ectoplasm, Ocean, Coffee), set the scheme on the admin user and read the computedcolorof each element in normal, hover and keyboard-focus state. - Result:
.delete-linkhas no styles on trunk. It looks exactly like the plain link in every scheme, as expected for a new class.
With patch applied
- Applied the PR (applies cleanly), rebuilt the color schemes and repeated step 2.
- Default (
modern), Light, Blue, Midnight, Sunrise, Ectoplasm, Ocean, Coffee: ✅.delete-linkis#cc1818and darkens to#9e1313on hover and focus, the same as.button-link-deletein each scheme. - Fresh:
.delete-linkis still the normal blue link color (#2271b1, hover#135e96). Fresh is registered with no stylesheet (wp_admin_css_color( 'fresh', …, false, … )), so nothing fromcolors/_admin.scssreaches it. In Fresh,.button-link-deletegets its red (#d63638) fromwp-includes/css/buttons.cssinstead. Fresh is no longer the default (users were moved tomoderninupgrade_700()), but it is still offered second in the profile's color picker. The PR description says "every admin page loads a compiled color scheme", which is true for every scheme except Fresh. - As a check, I added
.wp-core-ui .delete-link(plus:hoverand:focus) next to the.button-link-deleterules inwp-includes/css/buttons.css(diff in Support Content). With that change,.delete-linkis red in Fresh too, and the color-scheme rules still win in the other schemes. - Existing
.button-link-deletebuttons look the same with the patch in every scheme.
Screenshot (top: PR in the Default scheme; bottom: PR in Fresh): https://files.catbox.moe/6fw58y.png
✅ Patch is solving the problem
The class works in the Default scheme and in seven of the other eight. The one gap is Fresh, where .delete-link has no effect while .button-link-delete is still red. Adding the selector to wp-includes/css/buttons.css next to .button-link-delete (step 7) would make it work in every scheme.
Notes:
- @joedolson's request in comment:25, a style for destructive buttons that are not styled as links (for example "Delete Permanently" in the media grid), is not covered by either PR.
- Two other open PRs are linked to this ticket: #11519 (older, and also changes many core screens) and #12449, which changes
class-wp-scripts.phpand looks linked to the wrong ticket. - Not covered: RTL, Windows High Contrast mode, and the minified build (
buttons.min.css). I tested withSCRIPT_DEBUGon.
AI disclosure
- AI assistance: Yes
- Tool(s): Claude Code (Claude Opus 5.5)
- Used for: writing the test page and the browser script that reads the computed colors, running the tests and drafting this report. I also checked the test page by hand:
.delete-linkis red in the Default scheme and stays blue in Fresh. I reviewed and edited the report before posting.
Support Content
MU plugin wp-content/mu-plugins/test-trac-36882.php:
<?php /** * Plugin Name: Trac 36882 test page (MU) * Description: Adds Tools > Trac 36882 with a destructive link using the proposed .delete-link class, * next to the existing .button-link-delete button and a plain link for comparison. */ add_action( 'admin_menu', function () { add_management_page( 'Trac 36882', 'Trac 36882', 'manage_options', 'trac-36882', function () { ?> <div class="wrap"> <h1>Trac 36882: destructive action styles</h1> <p><a href="#" id="t-plain">Plain link (control)</a></p> <p><a href="#" id="t-delete-link" class="delete-link">Delete permanently (.delete-link)</a></p> <p><button type="button" id="t-button-link-delete" class="button-link button-link-delete">Delete permanently (.button-link.button-link-delete)</button></p> <p><button type="button" id="t-button-delete-only" class="button-link-delete">Delete (.button-link-delete only)</button></p> </div> <?php } ); } );
Manual check: switch Users > Profile > Admin Color Scheme between Default and Fresh, and open Tools > Trac 36882.
Computed colors (normal / hover / focus):
Scheme Element trunk PR 13265 PR 13265 + buttons.css Default .delete-link #3858e9 #183ad6 #183ad6 #cc1818 #9e1313 #9e1313 #cc1818 #9e1313 #9e1313 Default .button-link-delete #cc1818 #9e1313 #9e1313 #cc1818 #9e1313 #9e1313 #cc1818 #9e1313 #9e1313 Fresh .delete-link #2271b1 #135e96 #043959 #2271b1 #135e96 #043959 #d63638 #d63638 #d63638 Fresh .button-link-delete #d63638 #d63638 #d63638 #d63638 #d63638 #d63638 #d63638 #d63638 #d63638 Light/Blue/Midnight/Sunrise/Ectoplasm/Ocean/Coffee: same pattern as Default (.delete-link #0073aa on trunk, #cc1818 / #9e1313 with the PR)
Suggested addition so .delete-link also works in the Fresh scheme, which loads no color-scheme stylesheet (src/wp-includes/css/buttons.css, next to the existing .button-link-delete rules; the other schemes are unaffected because their own stylesheet still sets the color):
-
src/wp-includes/css/buttons.css
a b TABLE OF CONTENTS: 247 247 outline: 1px solid transparent; 248 248 } 249 249 250 .wp-core-ui .button-link-delete { 250 .wp-core-ui .button-link-delete, 251 .wp-core-ui .delete-link { 251 252 color: #d63638; 252 253 } 253 254 254 255 .wp-core-ui .button-link-delete:hover, 255 .wp-core-ui .button-link-delete:focus { 256 .wp-core-ui .button-link-delete:focus, 257 .wp-core-ui .delete-link:hover, 258 .wp-core-ui .delete-link:focus { 256 259 color: #d63638; 257 260 background: transparent; 258 261 }
This ticket was mentioned in Slack in #core by im3dabasia1. View the logs.
5 weeks ago
#31
@
5 weeks ago
As per today’s 7.2 bug scrub:
We’re approaching beta 1, and I see some testing activity since the needs-testing keyword was added, which is good. @joedolson, are we in line for 7.2 on this? If it’s not a priority, we can punt it to 7.3.
Related: #35126.