Opened 8 years ago
Last modified 5 weeks ago
#44082 new defect (bug)
settings_errors() wraps all notices in p and strong tags
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch 2nd-opinion has-screenshots |
| 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 usestrongfor 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 (2)
Change History (4)
#1
@
5 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.
#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).
#2
@
5 weeks ago
- Keywords 2nd-opinion has-screenshots added; needs-testing removed
Patch Testing Report
Patch Tested: https://core.trac.wordpress.org/attachment/ticket/44082/44082.diff
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 144.0.0.0
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins:
- test-settings-errors.php
- Plugins:
- Test Reports 1.2.1
Steps taken
Created a plugin to demonstrate various cases
- Download https://core.trac.wordpress.org/attachment/ticket/44082/test-settings-errors.php.zip and install as mu plugin
- Navigate to Settings > Test Settings Errors
- View error messages and their generated source codes
- Apply patch
- View error messages and their generated source codes again
- ✅ Patch is solving the problem.
Expected result
- We are expecting
wpautopto fix formatting inconsistencies and avoid duplication ofptags.


wpautop() option