Make WordPress Core

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: johnjamesjacoby's profile johnjamesjacoby 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 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 (2)

44082.diff (455 bytes) - added by sabernhardt 5 years ago.
wpautop() option
test-settings-errors.php.zip (2.1 KB) - added by ozgursar 5 weeks ago.
MU Plugin for testing various cases

Download all attachments as: .zip

Change History (4)

@sabernhardt
5 years ago

wpautop() option

#1 @sabernhardt
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).

Version 0, edited 5 years ago by sabernhardt (next)

@ozgursar
5 weeks ago

MU Plugin for testing various cases

#2 @ozgursar
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

  1. Download https://core.trac.wordpress.org/attachment/ticket/44082/test-settings-errors.php.zip and install as mu plugin
  2. Navigate to Settings > Test Settings Errors
  3. View error messages and their generated source codes
  4. Apply patch
  5. View error messages and their generated source codes again
  6. ✅ Patch is solving the problem.

Expected result

  • We are expecting wpautop to fix formatting inconsistencies and avoid duplication of p tags.

Screenshots/Screencast with results

Before:
https://files.catbox.moe/0s52vi.png

After:
https://files.catbox.moe/90jphu.png

Note: See TracTickets for help on using tickets.