Make WordPress Core


Ignore:
Timestamp:
10/10/2026 02:18:37 PM (4 days ago)
Author:
joedolson
Message:

Admin: Admin notice accessibility improvements.

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 ​https://github.com/WordPress/wordpress-develop/pull/13671.

Props afercia, psykro, ryokuhi, raaaahman, alexstine, sergeybiryukov, oglekler, marybaum, swissspidy, davidbaumwald, sanket.parmar, sabernhardt, peterwilsoncc, williampatton, im3dabasia1, audrasjb, khokansardar, ugyensupport, joedolson.
Fixes #50486.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/common.js

    r64133 r64282  
    10761076        }
    10771077
    1078         /*
    1079          * The `.below-h2` class is here just for backward compatibility with plugins
    1080          * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570.
    1081          * If '.wp-header-end' is found, append the notices after it otherwise
    1082          * after the first h1 or h2 heading found within the main content.
    1083          */
    1084         if ( ! $headerEnd.length ) {
    1085                 $headerEnd = $( '.wrap h1, .wrap h2' ).first();
    1086         }
    1087         $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd );
    1088 
    10891078        /**
    10901079         * Makes notices dismissible.
    … …  
    15251514                input.on('change', toggleUploadButton);
    15261515        })();
     1516
     1517        /**
     1518         * Moves the admin notices into an `aside` element after the first `h1`.
     1519         * Prior to 7.2.0, admin notices were only moved after the first `h1`;
     1520         * The `aside` wrapper was added in 7.2.0.
     1521         *
     1522         * @since 7.2.0
     1523         *
     1524         * @return {void}
     1525         */
     1526        function moveAdminNotices() {
     1527                /*
     1528                 * The `.below-h2` class is here just for backward compatibility with plugins
     1529                 * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570.
     1530                 * If '.wp-header-end' is found, append the notices after it otherwise
     1531                 * after the first h1 or h2 heading found within the main content.
     1532                 */
     1533                if ( ! $headerEnd.length ) {
     1534                        $headerEnd = $( '.wrap h1, .wrap h2' ).first();
     1535                }
     1536                const $notices = $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' );
     1537                if ( $notices.length ) {
     1538                        const $wpAdminNotices = $( '<aside id="wp-admin-notices"></aside>' ).attr( 'aria-label', __( 'Admin Notices' ) ).insertAfter( $headerEnd );
     1539                        $notices.appendTo( $wpAdminNotices );
     1540                }
     1541        }
    15271542
    15281543        /**
    … …  
    21282143
    21292144        window.wpResponsive.init();
     2145        moveAdminNotices();
    21302146        setPinMenu();
    21312147        setMenuState();
Note: See TracChangeset for help on using the changeset viewer.