Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#18368 closed feature request (wontfix)

Add CSS Class Info to post_updated_messages array/filter

Reported by: cgrymala Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.2.1
Component: Editor Keywords: has-patch dev-feedback
Focuses: Cc:


When saving a post, not all messages displayed on the screen are "success" messages. Some are errors or warnings. Therefore, it would be nice to have the ability to modify the CSS class that's applied to the notice message.

In order to support backwards-compatibility, I would suggest allowing the array that's built using the post_updated_messages filter to support strings (which would be the message text by itself) or arrays (which would include one item for the message text and one item for the message class).

If a string is found, that string is assigned as the message text. If an array is found, the first item is assigned as the message text and the second item is assigned as the message class.

If a message class is not defined, the CSS class of 'updated' is used; if it is found, the specified CSS class is used.

I've attached a patch for wp-admin/edit-form-advanced.php showing basically what I'm proposing. In this case, if an array is sent as the value of one of the messages, that array is expected to use the keys "message" and "class"; but it could certainly be edited just to use numeric keys if that might make more sense.

Attachments (1)

updated_post_message-css_class.patch (1.6 KB) - added by cgrymala 7 years ago.
Allows a CSS class to be assigned to an updated post message

Download all attachments as: .zip

Change History (5)

7 years ago

Allows a CSS class to be assigned to an updated post message

#1 @nacin
7 years ago

It'd probably be better to leverage WP_Error here.

Not entirely sure though when .error would be desired. Doesn't seem like core would use it.

#2 @westi
7 years ago

Not really sure we need this here.

The filter is for update messages not really for errors.

#3 @cgrymala
7 years ago

My thought behind this was that there are some plugins that make some elements of a post (especially custom fields or taxonomies) required in order to actually publish it. If those elements don't have values, they won't let the post get published; it gets saved as a draft, instead.

In those instances (and there are probably others), the style of the "message" is a bit deceiving; since the "This post was not published" type of message is forced to have the same style as the "The post was published successfully" type of message.

I understand that there are no instances (at least, yet) in the core that would need to use this; but I just thought it would be a nice, simple way to allow plugin authors to extend the way the messages are displayed.

#4 @nacin
4 years ago

  • Component changed from Warnings/Notices to Editor
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I think it's safe to close this out for now. It's not a bad idea per se, but it seems there is little interest in implementing it.

Note: See TracTickets for help on using tickets.