Repository navigation
Conversation
This can also be used potentially to get notices to a separate display context. Captures all non-empty messages. Messages with no text are assumed to be placeholders for JS-driven messages to be generated later.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@pattonwebz @afercia This is a rough draft of some alternative implementation for notices. Not thoroughly tested at this phase, but feel free to hammer at it. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| if ( $notices.length ) { | ||
| var $wpAdminNotices = $( '<aside id="wp-admin-notices"></aside>' ).attr( 'aria-label', __( 'Admin Notices' ) ).insertAfter( $headerEnd ); | ||
| $notices.appendTo( $wpAdminNotices ); | ||
| } |
There was a problem hiding this comment.
I'd consider to wrap this in a named function (with a docblock), for clarity. Then call the function at the bottom of the wrapping IIFE where other functions are called e.g. setPinMenu();.
There was a problem hiding this comment.
Seems reasonable. This code is quite old, and I don't see any evidence that there was a reason for it to be run where it is.
| 'markup' => $markup, | ||
| 'message' => $message, | ||
| 'args' => $args, | ||
| ); |
There was a problem hiding this comment.
I understand this class and method have been designed for a generic implementation but why it is building an object with the markup, message, and args? To my understanding, they are never used. If I'm not missing anything, the $notices array is only used to count the notices.
It so, there is no need to get the markup/message/args. We could also consider to not use the wp_admin_notice_markup filter and use the wp_admin_notice action hook instead.
There was a problem hiding this comment.
I was hypothesizing that this could also be used to build out a list of notices that could be triggered, e.g. from the admin bar, to be able to browse notices. That's not something that's critical to implement in this PR, but I was experimenting with the implementation.
The wp_admin_notice action isn't viable, because it doesn't catch anything that uses a echo wp_get_admin_notice() or $message = wp_get_admin_notice() pattern.
|
Some more thoughts: So far, this PR only works for notices that are printed via Other notices will not be collected. For example all the ones in the Settings pages that are rendered via There are other hooks that are used to render notices. As far as I can tell, they don't pass arguments, they are just hooks: As such, the notice can only be collected if the callback actually uses Extenders may not use Suggest for testing: test multiple notices on the same page. Test saving on one of the Settings pages:
|
|
After merging #13669 I tested a few more cases. All seem to be collected and counted correctly. A notice rendered directly in the middle of a page e.g. in the Reading Settings page: Two other notices hooked into hooks that fire late on a page: Other findings reported by @pattonwebz especially the 4th one on https://core.trac.wordpress.org/ticket/50486#comment:55 need to be tested more in depth. |
|
This intentionally doesn't capture any notices that aren't passed through In my opinion, directly printing a notice is |
Yes. It won't catch anything echoed when using However, we can try to add a new hook inside |
|
I'm not sure I see the value of a new hook. Can you specify how you see a duplicate happening with this? All calls to I can appreciate wanting to try to catch duplicates, I'm just not seeing how what you propose would do that. |
Nevermind, I think I understand a little better now. |
|
One more thing: For future extensibility, should we consider to make
This way, any notice generated by wp_get_admin_notice / wp_admin_notice would carry a unique identifier. That would be useful for any future extension e.g. a notification center. |
Sets all unique IDs as a `data-id`; if there is not ID attribute, sets as the ID attribute as well.
|
Updates add a unique ID to all generated notices and key the array to those IDs; I think the future potential for a notification center, or even just making that an easily plugged extension, is definitely worthwhile. I don't think that the issue about renderers is very significant; when we implemented wp_admin_notices(), we were pretty thorough in catching the output that was created. I believe that the only significant outliers are JS generated notices and the settings API errors, that you've already got a separate PR for. |
afercia
left a comment
There was a problem hiding this comment.
I left some minor comments.
|
One more thing worth considering. It's not strictly related to this PR and can be considered in a follow-up. As far as I can tell, the 4 admin notice types I would consider adding a const in the most appropriate class (the collector?) to have a canonical source for the types so that it can be referenced when needed e.g.:
then when in other parts of the codebase there is the need to get the Core notice types, this would be all that is needed
|
|
I can see some argument for having a canonical reference of notice types, but I agree that it's beyond the scope of this PR - it doesn't directly impact the accessibility of notices, just the stability of usage. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
While updating the tests yesterday to account for the new ID related attributes, I noticed that the data set an ID that is not a string does not include the id or data-id attributes. The invalid value is simply dropped.
If the argument passed is incorrect, I think the default attributes should be used in its place.
Capture all admin notices with message content generated via `wp_get_admin_notices()`. Wrap all captured notices inside an `aside` so notices are identified within a navigable landmark. Add information about the number of notices produced on a page in the `title` element of the page. Ensures users have awareness on page entry whether there are notices present, how many there are, and provides screen readers with a mechanism to locate them as a group. Inline notices are counted in the total, but not contained within the landmark. Developed in #13671. Props afercia, psykro, ryokuhi, raaaahman, alexstine, sergeybiryukov, oglekler, marybaum, swissspidy, davidbaumwald, sanket.parmar, sabernhardt, peterwilsoncc, williampatton, im3dabasia1, audrasjb, khokansardar, ugyensupport, joedolson. Fixes #50486. git-svn-id: https://develop.svn.wordpress.org/trunk@64282 602fd350-edb4-49c9-b593-d223f7449a82
Capture all admin notices with message content generated via `wp_get_admin_notices()`. Wrap all captured notices inside an `aside` so notices are identified within a navigable landmark. Add information about the number of notices produced on a page in the `title` element of the page. Ensures users have awareness on page entry whether there are notices present, how many there are, and provides screen readers with a mechanism to locate them as a group. Inline notices are counted in the total, but not contained within the landmark. Developed in WordPress/wordpress-develop#13671. Props afercia, psykro, ryokuhi, raaaahman, alexstine, sergeybiryukov, oglekler, marybaum, swissspidy, davidbaumwald, sanket.parmar, sabernhardt, peterwilsoncc, williampatton, im3dabasia1, audrasjb, khokansardar, ugyensupport, joedolson. Fixes #50486. Built from https://develop.svn.wordpress.org/trunk@64282 git-svn-id: http://core.svn.wordpress.org/trunk@63432 1a063a9b-81f0-0310-95a4-ce76da25c4cd
| * | ||
| * @package WordPress | ||
| * @subpackage Administration | ||
| * @since x.x.x |
There was a problem hiding this comment.
Let's push an additional commit to fix this to the correct version.
There was a problem hiding this comment.
I could have sworn I'd gotten all of those... apparently not!




This PR is an alternative to #11923.
This PR only attempts to handle notices that are passed through
wp_get_admin_notices(), with the intention that all core admin notices should do this. This simplifies the code by not attempting to capture all legacy variants that a notice could conceivably appear in.It doesn't capture JS produced notices, but those already need to be handled separately.
It doesn't attempt to render the notices in a different location in PHP, keeping the existing DOM relocation, but wrapping the notices that are moved in an
asideto provide better navigation.This doesn't include a conditional skip link to navigate to those, although that could be added.
It also doesn't add ARIA roles into the PHP produced notices - these should not be there; ARIA is only necessary for empty notices where information will be inserted or modified with JS.
This should be considered a draft, although reviews are welcome. It is not in any way ready for merge.
Trac ticket: https://core.trac.wordpress.org/ticket/50486
Use of AI Tools
AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): Claude Sonnet
Used for: Initial code skeleton; final implementation was reviewed and significantly modified by me.
-->
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.