[wp-trac] [WordPress Trac] #55537: Pair wpAjax admin notices with accessible audible messages

WordPress Trac noreply at wordpress.org
Thu Apr 7 10:44:15 UTC 2022

#55537: Pair wpAjax admin notices with accessible audible messages
 Reporter:  afercia               |       Owner:  (none)
     Type:  enhancement           |      Status:  new
 Priority:  normal                |   Milestone:  Awaiting Review
Component:  Administration        |     Version:
 Severity:  normal                |  Resolution:
 Keywords:  has-patch needs-      |     Focuses:  accessibility, javascript
  testing                         |
Changes (by afercia):

 * keywords:   => has-patch needs-testing


 [attachment:"55537.diff"] adds accessible audible messages to three more
 cases in `ajax-response.js` where admin notices are displayed, so that the
 visual notices are paired with audible messages.

 Following the code in `wpAjax.parseAjaxResponse`, see

 It first checks whether it's a `WP_Ajax_Response` xml response, handles
 the response and returns it. After that, there are 3 more cases:
 - `isNaN(x)`: the response is not a number. Rather, it's a string.
 Typically, a custom message passed to `wp_die()` e.g. `wp_die( __( 'Some
 error message' ) )`.
 - `-1 === x`: this is when `wp_die( -1 )` is used and it's associated with
 the default message 'Sorry, you are not allowed to do that.'.
 - `0 === x`: this is when `wp_die( 0 )` is used and it's associated with
 the default message 'Something went wrong.'.

 Worth noting that in all these three cases, the existing code already
 displays some text in an admin notice.

 This patch just uses the same text displayed in the admin notice to
 trigger an audible message for screen reader users via `wp.a11y.speak()`.

 - Adds a missing script dependency. Note that this is tracked also in
 - Updates the CSS classes for the admin notices. `error` and `updated` are
 legacy classes and should not be used any longer. Since a few years, the
 admin notices use a new pattern e.g. `notice notice-error`, `notice
 notice-success`, etc.

 To test:
 I can't think of an easy way to test this other than altering the code.
 For example:
 - In the `wp_ajax_add_tag()` function, before the creation of the
 `WP_Ajax_Response` instance, add the following code: `wp_die( -1 );`
 - Go to the Categories or Tags page.
 - Submit the form.
 - Check an admin notice with text 'Sorry, you are not allowed to do that.'
 is displayed at the top of the page.
 - Use your browser's dev tools inspector and check the same text is in the
 ARIA live region with  id `a11y-speak-polite`.
 - Change `wp_die( -1 );` to `wp_die( 0 );` and repeat the test. The
 message text will be 'Something went wrong.'.
 - Change `wp_die( 0 );` to `wp_die( __( 'My custom message' ) );` and
 repeat the test. Of course, the message text will be 'My custom message'.

Ticket URL: <https://core.trac.wordpress.org/ticket/55537#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list