Skip to content

Commit a25196c

Browse files
committed
Conditionally set aria-describedby on the fieldset and more a11y improvements.
1 parent 1a92ee5 commit a25196c

2 files changed

Lines changed: 42 additions & 33 deletions

File tree

‎src/wp-admin/install.php‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function display_setup_form( $error = null ) {
103103
$admin_email = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
104104

105105
if ( ! is_null( $error ) ) {
106+
106107
?>
107108
<h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
108109
<p class="message"><?php echo $error; ?></p>
@@ -114,20 +115,19 @@ function display_setup_form( $error = null ) {
114115
<td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
115116
</tr>
116117
<tr>
117-
<th scope="row"><label for="user_login"><?php _e( 'Username' ); ?></label></th>
118-
<td>
119-
<?php
120-
if ( $user_table ) {
121-
_e( 'User(s) already exists.' );
122-
echo '<input name="user_name" type="hidden" value="admin" />';
123-
} else {
124-
?>
125-
<input name="user_name" type="text" id="user_login" size="25" aria-describedby="user-name-desc" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
126-
<p id="user-name-desc"><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods, and the @ symbol.' ); ?></p>
127-
<?php
128-
}
129-
?>
130-
</td>
118+
<?php if ( $user_table ) : ?>
119+
<th scope="row"><?php _e( 'Username' ); ?></th>
120+
<td>
121+
<?php _e( 'User(s) already exists.' ); ?>
122+
<input name="user_name" type="hidden" value="admin" />
123+
</td>
124+
<?php else : ?>
125+
<th scope="row"><label for="user_login"><?php _e( 'Username' ); ?></label></th>
126+
<td>
127+
<input name="user_name" type="text" id="user_login" size="25" aria-describedby="user-name-desc" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
128+
<p id="user-name-desc"><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods, and the @ symbol.' ); ?></p>
129+
</td>
130+
<?php endif; ?>
131131
</tr>
132132
<?php if ( ! $user_table ) : ?>
133133
<tr class="form-field form-required user-pass1-wrap">
@@ -179,28 +179,32 @@ function display_setup_form( $error = null ) {
179179
<td><input name="admin_email" type="email" id="admin_email" size="25" aria-describedby="admin-email-desc" value="<?php echo esc_attr( $admin_email ); ?>" />
180180
<p id="admin-email-desc"><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
181181
</tr>
182-
<?php $blog_privacy_selector_title = has_action( 'blog_privacy_selector' ) ? __( 'Site visibility' ) : __( 'Search engine visibility' ); ?>
182+
<?php
183+
$has_action_blog_privacy_selector = has_action( 'blog_privacy_selector' );
184+
$blog_privacy_selector_title = $has_action_blog_privacy_selector ? __( 'Site visibility' ) : __( 'Search engine visibility' );
185+
$fieldset_aria_describedby = $has_action_blog_privacy_selector ? ' aria-describedby="options-site-visibility-description"' : '';
186+
?>
183187
<tr>
184-
<th scope="row"><?php echo $blog_privacy_selector_title; ?></th>
188+
<th scope="row"><?php echo esc_html( $blog_privacy_selector_title ); ?></th>
185189
<td>
186-
<fieldset>
187-
<legend class="screen-reader-text"><span><?php echo $blog_privacy_selector_title; ?></span></legend>
190+
<fieldset<?php echo $fieldset_aria_describedby; ?>>
191+
<legend class="screen-reader-text"><?php echo esc_html( $blog_privacy_selector_title ); ?></legend>
188192
<?php
189-
if ( has_action( 'blog_privacy_selector' ) ) {
193+
if ( $has_action_blog_privacy_selector ) {
190194
?>
191195
<input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> />
192196
<label for="blog-public"><?php _e( 'Allow search engines to index this site' ); ?></label><br />
193-
<input id="blog-norobots" type="radio" name="blog_public" aria-describedby="public-desc" value="0" <?php checked( 0, $blog_public ); ?> />
197+
<input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( 0, $blog_public ); ?> />
194198
<label for="blog-norobots"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
195-
<p id="public-desc" class="description"><?php _e( 'Note: Discouraging search engines does not block access to your site &mdash; it is up to search engines to honor your request.' ); ?></p>
199+
<p id="options-site-visibility-description" class="description"><?php _e( 'Note: Discouraging search engines does not block access to your site &mdash; it is up to search engines to honor your request.' ); ?></p>
196200
<?php
197201
/** This action is documented in wp-admin/options-reading.php */
198202
do_action( 'blog_privacy_selector' );
199203
} else {
200204
?>
201-
<label for="blog_public"><input name="blog_public" type="checkbox" id="blog_public" aria-describedby="privacy-desc" value="0" <?php checked( 0, $blog_public ); ?> />
202-
<?php _e( 'Discourage search engines from indexing this site' ); ?></label>
203-
<p id="privacy-desc" class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
205+
<input name="blog_public" type="checkbox" id="blog_public" aria-describedby="options-site-visibility-description" value="0" <?php checked( 0, $blog_public ); ?> />
206+
<label for="blog_public"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
207+
<p id="options-site-visibility-description" class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
204208
<?php } ?>
205209
</fieldset>
206210
</td>

‎src/wp-admin/options-reading.php‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// Used in the HTML title tag.
1717
$title = __( 'Reading Settings' );
1818
$parent_file = 'options-general.php';
19+
// Check whether the blog_privacy_selector action is in use, for later reuse.
20+
$has_action_blog_privacy_selector = has_action( 'blog_privacy_selector' );
1921

2022
add_action( 'admin_head', 'options_reading_add_js' );
2123

@@ -41,7 +43,7 @@
4143
get_current_screen()->add_help_tab(
4244
array(
4345
'id' => 'site-visibility',
44-
'title' => has_action( 'blog_privacy_selector' ) ? __( 'Site visibility' ) : __( 'Search engine visibility' ),
46+
'title' => $has_action_blog_privacy_selector ? __( 'Site visibility' ) : __( 'Search engine visibility' ),
4547
'content' => '<p>' . __( 'You can choose whether or not your site will be crawled by robots, ping services, and spiders. If you want those services to ignore your site, click the checkbox next to &#8220;Discourage search engines from indexing this site&#8221; and click the Save Changes button at the bottom of the screen.' ) . '</p>' .
4648
'<p>' . __( 'Note that even when set to discourage search engines, your site is still visible on the web and not all search engines adhere to this directive.' ) . '</p>' .
4749
'<p>' . __( 'When this setting is in effect, a reminder is shown in the At a Glance box of the Dashboard that says, &#8220;Search engines discouraged&#8221;, to remind you that you have directed search engines to not crawl your site.' ) . '</p>',
@@ -206,17 +208,20 @@
206208
</fieldset></td>
207209
</tr>
208210

209-
<?php $blog_privacy_selector_title = has_action( 'blog_privacy_selector' ) ? __( 'Site visibility' ) : __( 'Search engine visibility' ); ?>
211+
<?php
212+
$blog_privacy_selector_title = $has_action_blog_privacy_selector ? __( 'Site visibility' ) : __( 'Search engine visibility' );
213+
$fieldset_aria_describedby = $has_action_blog_privacy_selector ? ' aria-describedby="option-site-visibility-description"' : '';
214+
?>
210215
<tr class="option-site-visibility">
211216
<th scope="row"><?php echo $blog_privacy_selector_title; ?> </th>
212-
<td><fieldset>
217+
<td><fieldset<?php echo $fieldset_aria_describedby; ?>>
213218
<legend class="screen-reader-text"><span><?php echo $blog_privacy_selector_title; ?></span></legend>
214-
<?php if ( has_action( 'blog_privacy_selector' ) ) : ?>
219+
<?php if ( $has_action_blog_privacy_selector ) : ?>
215220
<input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( '1', get_option( 'blog_public' ) ); ?> />
216221
<label for="blog-public"><?php _e( 'Allow search engines to index this site' ); ?></label><br />
217-
<input id="blog-norobots" type="radio" name="blog_public" aria-describedby="public-desc" value="0" <?php checked( '0', get_option( 'blog_public' ) ); ?> />
222+
<input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( '0', get_option( 'blog_public' ) ); ?> />
218223
<label for="blog-norobots"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
219-
<p id="public-desc" class="description"><?php _e( 'Note: Neither of these options blocks access to your site &mdash; it is up to search engines to honor your request.' ); ?></p>
224+
<p id="option-site-visibility-description" class="description"><?php _e( 'Note: Neither of these options blocks access to your site &mdash; it is up to search engines to honor your request.' ); ?></p>
220225
<?php
221226
/**
222227
* Enables the legacy 'Site visibility' privacy options.
@@ -235,9 +240,9 @@
235240
do_action( 'blog_privacy_selector' );
236241
?>
237242
<?php else : ?>
238-
<label for="blog_public"><input name="blog_public" type="checkbox" id="blog_public" aria-describedby="privacy-desc" value="0" <?php checked( '0', get_option( 'blog_public' ) ); ?> />
239-
<?php _e( 'Discourage search engines from indexing this site' ); ?></label>
240-
<p id="privacy-desc" class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
243+
<input name="blog_public" type="checkbox" id="blog_public" aria-describedby="option-site-visibility" value="0" <?php checked( '0', get_option( 'blog_public' ) ); ?> />
244+
<label for="blog_public"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
245+
<p id="option-site-visibility-description" class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
241246
<?php endif; ?>
242247
</fieldset></td>
243248
</tr>

0 commit comments

Comments
 (0)