Make WordPress Core

Opened 6 years ago

Last modified 4 years ago

#44082 new defect (bug)

settings_errors() wraps all notices in p and strong tags

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch needs-testing
Focuses: Cc:

Description

I noticed today that settings_errors() wraps every notice in a set of <p> and <strong> tags.

This is undesirable for a few reasons:

  • Notices should be allowed to use their own formatting (they already are everywhere)
  • Many/most core notices that do not use settings_errors() are not strong, or use strong for emphasizing specific parts of a notice

As a result, almost every plugin is forced to reinvent their own approach for putting out admin notices. Core even does this in a bespoke way in almost every other admin page, resulting in a bunch of duplication and fragmentation of approaches.

(A quick grep of .php files in wp-admin with is-dismissible in them shows 75.)


A few ideas:

  • We could use wpautop() to wrap each notice to avoid duplicate <p> tags
  • We could use KSES to only allow certain tags in a notice (not certain this is necessary)
  • We could invent a new function for formatting admin area notices in places other than settings (which most plugins do already, so something they can use is preferable)

I can also imagine this issue being a smaller part of a larger admin_notices initiative, but figured I'd at least document this kvetch.

Attachments (1)

44082.diff (455 bytes) - added by sabernhardt 4 years ago.
wpautop() option

Download all attachments as: .zip

Change History (2)

@sabernhardt
4 years ago

wpautop() option

#1 @sabernhardt
4 years ago

  • Keywords has-patch needs-testing added

44082.diff follows the proposed change of using wpautop, to see if the simplest method is good. I've done a quick test so far, but I haven't tried to break it.

I also thought of adding another parameter to the function ($formatted = false) to keep the current markup by default. (I'm not convinced that's a better idea.)

#38734 already reported how core is not using the Settings API (and my search of the current trunk found 89 is-dismissible notices in wp-admin).

Last edited 4 years ago by sabernhardt (previous) (diff)
Note: See TracTickets for help on using tickets.