@@ -1852,24 +1852,28 @@ function do_settings_fields( $page, $section ) {
18521852 *
18531853 * @since 3.0.0
18541854 * @since 5.3.0 Added `warning` and `info` as possible values for `$type`.
1855+ * @since 6.9.0 Added `$aria_live` parameter to control the screen reader announcement.
18551856 *
18561857 * @global array[] $wp_settings_errors Storage array of errors registered during this pageload
18571858 *
1858- * @param string $setting Slug title of the setting to which this error applies.
1859- * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1860- * @param string $message The formatted message text to display to the user (will be shown inside styled
1859+ * @param string $setting Slug title of the setting to which this error applies.
1860+ * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1861+ * @param string $message The formatted message text to display to the user (will be shown inside styled
18611862 * `<div>` and `<p>` tags).
18621863 * @param string $type Optional. Message type, controls HTML class. Possible values include 'error',
18631864 * 'success', 'warning', 'info'. Default 'error'.
1865+ * @param string $aria_live Optional. The ARIA live attribute value. Possible values include 'off', 'polite',
1866+ * 'assertive'. Default empty string which doesn't add the attribute.
18641867 */
1865- function add_settings_error ( $ setting , $ code , $ message , $ type = 'error ' ) {
1868+ function add_settings_error ( $ setting , $ code , $ message , $ type = 'error ' , $ aria_live = '' ) {
18661869 global $ wp_settings_errors ;
18671870
18681871 $ wp_settings_errors [] = array (
1869- 'setting ' => $ setting ,
1870- 'code ' => $ code ,
1871- 'message ' => $ message ,
1872- 'type ' => $ type ,
1872+ 'setting ' => $ setting ,
1873+ 'code ' => $ code ,
1874+ 'message ' => $ message ,
1875+ 'type ' => $ type ,
1876+ 'aria_live ' => $ aria_live ,
18731877 );
18741878}
18751879
@@ -2009,7 +2013,12 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa
20092013 esc_attr ( $ details ['type ' ] )
20102014 );
20112015
2012- $ output .= "<div id=' $ css_id' class=' $ css_class'> \n" ;
2016+ $ aria_live_attr = '' ;
2017+ if ( ! empty ( $ details ['aria_live ' ] ) && in_array ( $ details ['aria_live ' ], array ( 'off ' , 'polite ' , 'assertive ' ), true ) ) {
2018+ $ aria_live_attr = sprintf ( ' aria-live="%s" ' , esc_attr ( $ details ['aria_live ' ] ) );
2019+ }
2020+
2021+ $ output .= "<div id=' $ css_id' class=' $ css_class' $ aria_live_attr> \n" ;
20132022 $ output .= "<p><strong> {$ details ['message ' ]}</strong></p> " ;
20142023 $ output .= "</div> \n" ;
20152024 }
0 commit comments