Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#30199 closed enhancement (duplicate)

Add handling of a admin notice type "warning" to the WP admin.

Reported by: wedi's profile wedi Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Administration Keywords:
Focuses: ui, administration Cc:


I'd like to suggest adding CSS for an admin notice type warning to the WP Admin styles to allow nice formating and correct box movement of the following:

  1. Calling add_settings_error() with $type = 'warning' while working with the Settings API.
  2. echo '<div class="warning"><p>A word of warning!</p></div>'; in a admin_notice hook callback.

Right now, when a plugin author wants to display a warning message (e.g., a value that looks dangerous or cannot be verified) he has two options of which both are ugly:

  1. Hijack the update-nag class. Displays a yellow border which is nice for a warning but has different margin/padding assigned and gets not moved below the H2.
  2. Use an own class, add own css to admin, add own JS to admin to move the box. Works but requires a lot of work for a cosmetic issue and multiple mixed messages of builtin and own types will loose their ordering as error and updated message boxes get moved when builtin JS runs and own class is either before or after that when cutom JS runs.

The patch attached adds the neccessary CSS and JS as well as documentation for add_settings_error().

A different approach to the provided patch would be introducing a new class admin-notice which gets all message box styles applied and triggers moving by the JS in common.js and error and updated are reduced to applying the border colour. This would also reduce some duplicated CSS and allow for adding more box types (e.g. a blue notice box, a green box of envy, ...) easily.

So much text for such a small change... It's my first patch for WordPress so please be kind if I made a mistake. :)

Attachments (1)

admin_notice_warning.diff (3.8 KB) - added by wedi 10 years ago.

Download all attachments as: .zip

Change History (3)

#1 @wedi
10 years ago

What's missing are the minified versions of the changed CSS and JS files as I don't know the workflow yet.

And the code to reproduce:

add_action( 'admin_notices', 'test_admin_notice_display' );
public static function test_admin_notice_display() {
	echo '<div class="error"><p>An "error" message!</p></div>';
	echo '<div class="updated"><p>An "updated" message!</p></div>';
	echo '<div class="warning"><p>A "warning" message!</p></div>';
	echo '<div class="update-nag"><p>A "update-nag" message!</p></div>';
Version 1, edited 10 years ago by wedi (previous) (next) (diff)

#2 @kpdesign
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @wedi, thanks for the report and patch!

I've marked this ticket as a duplicate of #27418, as there is an ongoing discussion (and a patch) for a warning notice there.

Note: See TracTickets for help on using tickets.