Make WordPress Core

Opened 11 years ago

Closed 4 weeks ago

Last modified 4 weeks ago

#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)

#1 @swissspidy
11 years ago

  • Component General → Administration
  • Focuses administration removed

#2 @afercia
10 years ago

Related: #35126.

#3 @afercia
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.

#4 @flixos90
10 years ago

  • Milestone Awaiting Review → 4.8

#5 @jbpaul17
10 years ago

  • Keywords needs-patch added

This ticket was mentioned in ​Slack in #core by jeffpaul. ​View the logs.


10 years ago

#7 @jbpaul17
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 @afercia
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 @jbpaul17
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 @jbpaul17
9 years ago

  • Milestone 4.9 → Future Release

Punting to Future Release per today's 4.9 bug scrub.

#14 @joedolson
3 years ago

  • Owner set to joedolson
  • Status new → accepted

This ticket was mentioned in ​Slack in #accessibility by joedolson. ​View the logs.


8 months ago

#16 @joedolson
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

#18 @sukhendu2002
4 months ago

  • Keywords needs-patch added; has-patch has-unit-tests removed

#19 @wildworks
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 @joedolson
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

#22 @joedolson
4 months ago

  • Milestone 7.1 → 7.2

Now that the milestone field is fixed, punting to 7.2.

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-link alongside .button-link-delete in the admin color scheme (_admin.scss), for both the base color and the hover/focus color.

Approach and why:

  • The admin <body> carries the wp-core-ui class and every admin page loads a compiled color scheme, so .wp-core-ui .delete-link is available on any admin page, including custom plugin/theme screens — no separate common.css rule is needed.
  • Color-only rule (no base styling): unlike .button-link-delete, which needs .button-link to 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-red token 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 @khokansardar
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 @joedolson
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-link admin CSS class for destructive action links.
  • Mirrors the existing .button-link-delete color 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-link uses the alert-red color in an admin screen
  • [ ] Confirm hover/focus lightens/darkens consistently with .button-link-delete
  • [ ] Confirm existing .button-link-delete buttons 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 @audrasjb
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 @sajib1223
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_DEBUG on
  • 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

  1. Added a test admin page with a plain link, a link using the proposed .delete-link class, and a <button class="button-link button-link-delete"> for comparison.
  2. 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 computed color of each element in normal, hover and keyboard-focus state.
  3. Result: .delete-link has no styles on trunk. It looks exactly like the plain link in every scheme, as expected for a new class.

With patch applied

  1. Applied the PR (applies cleanly), rebuilt the color schemes and repeated step 2.
  2. Default (modern), Light, Blue, Midnight, Sunrise, Ectoplasm, Ocean, Coffee: ✅ .delete-link is #cc1818 and darkens to #9e1313 on hover and focus, the same as .button-link-delete in each scheme.
  3. Fresh: .delete-link is still the normal blue link color (#2271b1, hover #135e96). Fresh is registered with no stylesheet (wp_admin_css_color( 'fresh', …, false, … )), so nothing from colors/_admin.scss reaches it. In Fresh, .button-link-delete gets its red (#d63638) from wp-includes/css/buttons.css instead. Fresh is no longer the default (users were moved to modern in upgrade_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.
  4. As a check, I added .wp-core-ui .delete-link (plus :hover and :focus) next to the .button-link-delete rules in wp-includes/css/buttons.css (diff in Support Content). With that change, .delete-link is red in Fresh too, and the color-scheme rules still win in the other schemes.
  5. Existing .button-link-delete buttons 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.php and looks linked to the wrong ticket.
  • Not covered: RTL, Windows High Contrast mode, and the minified build (buttons.min.css). I tested with SCRIPT_DEBUG on.

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-link is 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:  
    247247        outline: 1px solid transparent;
    248248}
    249249
    250 .wp-core-ui .button-link-delete {
     250.wp-core-ui .button-link-delete,
     251.wp-core-ui .delete-link {
    251252        color: #d63638;
    252253}
    253254
    254255.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 {
    256259        color: #d63638;
    257260        background: transparent;
    258261}

This ticket was mentioned in ​Slack in #core by im3dabasia1. ​View the logs.


5 weeks ago

#31 @im3dabasia1
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.

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


4 weeks ago

#33 @audrasjb
4 weeks ago

This patch looks good to ship at a glance. @joedolson are you confortable committing #36882 before beta 1? I can help if needed.

Note: this needs to be committed before beta 1 later today.

#34 @audrasjb
4 weeks ago

  • Resolution → fixed
  • Status accepted → closed

In 64603:

Administration: Add a reusable .delete-link CSS class.

This changeset adds a reusable .delete-link admin CSS class for destructive action links. This class mirrors the existing .button-link-delete color rules (base + hover/focus) in the admin color schemes. This enhancement gives plugin and theme authors a standard class instead of reusing unrelated core selectors or copying link styles by hand.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13265.

Props flixos90, afercia, joedolson, sukhendu2002, wildworks, khokansardar, audrasjb, sajib1223, im3dabasia1.
Fixes #36882.

#35 @audrasjb
4 weeks ago

  • Keywords needs-dev-note add-to-field-guide added
Note: See TracTickets for help on using tickets.