Skip to content

Refactor settings_errors() to use wp_admin_notice() internally. - #13669

Closed
afercia wants to merge 10 commits into
WordPress:trunkfrom
afercia:admin-notices-a11y
Closed

afercia wants to merge 10 commits into
WordPress:trunkfrom
afercia:admin-notices-a11y

Conversation

@afercia

@afercia afercia commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/66161

Use of AI Tools

None


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props afercia, westonruter, joedolson.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@afercia
afercia requested a review from joedolson September 22, 2026 20:23
@afercia

afercia commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Cc @pattonwebz

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I would just remove testing for this and remove the workarounds I had to introduce to support this passed notice type.
But:
It was introduced in https://core.trac.wordpress.org/changeset/45873 to account for an edge case reported by... myself. Still, I'd consider to remove it also because wp_get_admin_notice() doesn't accept a type string that contains spaces.
Open to feedback.

Comment thread src/wp-admin/includes/template.php Outdated
if ( 'updated' === $details['type'] ) {
$details['type'] = 'success';
// Backward compatibility for passed types that may wrongly contain `notice-`.
$type = str_replace( 'notice-', '', trim( $details['type'] ) );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed types should no longer contain notice- as wp_get_admin_notice() already adds this prefix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this accidentally remove notice- from the unintended class? What if someone passs in a type like 'error my-notice-is-awesome hello world'?

Comment thread src/wp-admin/includes/template.php Outdated
$css_class = sprintf(
'notice %s settings-error is-dismissible',
esc_attr( $details['type'] )
esc_attr( $details['code'] ),

@westonruter westonruter Sep 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: This escaping is redundant. It is already handled by wp_get_admin_notice().

Suggested change
esc_attr( $details['code'] ),
$details['code'],

Comment thread src/wp-admin/includes/template.php Outdated
$additional_classes = explode( ' ', $type . ' settings-error' );
// Set the type to empty string.
$type = '';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment thread src/wp-admin/includes/template.php Outdated
if ( str_contains( $type, ' ' ) ) {
// Use ths substrings as additional classes.
$additional_classes = explode( ' ', $type . ' settings-error' );
// Set the type to empty string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obvious 😄

Suggested change
// Set the type to empty string.

Comment thread src/wp-admin/includes/template.php Outdated
if ( 'updated' === $details['type'] ) {
$details['type'] = 'success';
// Backward compatibility for passed types that may wrongly contain `notice-`.
$type = str_replace( 'notice-', '', trim( $details['type'] ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this accidentally remove notice- from the unintended class? What if someone passs in a type like 'error my-notice-is-awesome hello world'?

@afercia

afercia commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Currently, this PR introduces a change in the behavior for potential custom notice types.
Before, a passed type like for example calltoaction worked and was printed out without prefixing notice-.
After, it gets prefixed and becomes notice-calltoaction.

This is inherently the behavior of wp_admin_notice(() which always adds the notice- prefix.
A decision shoudl be made on whether to allow custom types without the notice- prefix.

@afercia

afercia commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

I addressed the backward compatibility issue in a hopefully better way and added more test cases. It covers cases when the $type passed to add_settings_error() may be like:

'error'
'success'
'warning'
'info'
'updated'
'notice-error'
'custom'
'notice-custom'
'error my-own-css-class hello world'
'error my-notice-is-awesome hello world'

This should cover the previous behavior.
Note that custom types may produce CSS classes that are rendered in a different order, but the classes are all there.

@afercia
afercia force-pushed the admin-notices-a11y branch 2 times, most recently from 32664c6 to 8ecee8f Compare September 23, 2026 22:24

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor change suggestion in a comment, for improved clarity. Otherwise, I think this looks good.

Comment thread src/wp-admin/includes/template.php Outdated
* classes are rendered in the default order determined by `wp_admin_notice()`.
* This includes the old type `updated`. Instead, anything else e.g.
* custom notice types or strings with spaces is now passed as
* additional_classes and appended to the end of the string,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it sound like $additional_classes is a string, when it's an array. I think you should limit the comment to addressing how custom classes are handled here, and not address how they will be handled once they're inside wp_admin_notices().

@afercia afercia added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Sep 26, 2026
@github-actions github-actions Bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Sep 26, 2026
wporg-sync pushed a commit that referenced this pull request Sep 26, 2026
The amdin notices rendered in the Settings pages use their own function to echo the notices, which is a little legacy. Today, Core provides a standardized way to render the admin notices by the means of `wp_admin_notice()`.

- Refactors `settings_errors()` to use `wp_admin_notice()` internally.
- Expands the related tests.

Added bonus: The Settings pages notices will now fire the some hooks and filters fired by `wp_admin_notice()`, e.g. `wp_admin_notice` and `wp_admin_notice_markup`, which is a necessary preparation for #50486.

Developed in #13669

Props afercia, westonruter, joedolson.
See #50486.
Fixes #66161.


git-svn-id: https://develop.svn.wordpress.org/trunk@63943 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 63943
GitHub commit: aaea5ab

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Sep 26, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 26, 2026
The amdin notices rendered in the Settings pages use their own function to echo the notices, which is a little legacy. Today, Core provides a standardized way to render the admin notices by the means of `wp_admin_notice()`.

- Refactors `settings_errors()` to use `wp_admin_notice()` internally.
- Expands the related tests.

Added bonus: The Settings pages notices will now fire the some hooks and filters fired by `wp_admin_notice()`, e.g. `wp_admin_notice` and `wp_admin_notice_markup`, which is a necessary preparation for #50486.

Developed in WordPress/wordpress-develop#13669

Props afercia, westonruter, joedolson.
See #50486.
Fixes #66161.

Built from https://develop.svn.wordpress.org/trunk@63943


git-svn-id: http://core.svn.wordpress.org/trunk@63109 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants