Accessibility: Add aria-current to the Archives, Categories, and Recent Posts widgets output.

The `aria-current` attribute is a simple, effective, way to help assistive technology users orientate themselves within a list of items.

Continues the introduction in core of the `aria-current` attribute after [41359] and following changes.

Props audrasjb, melchoyce.
Fixes #47094.

Built from https://develop.svn.wordpress.org/trunk@46163


git-svn-id: http://core.svn.wordpress.org/trunk@45975 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrea Fercia 2019-09-18 12:25:56 +00:00
parent b4ac30c19c
commit 095805b5e6
4 changed files with 18 additions and 11 deletions

View File

@ -206,6 +206,7 @@ class Walker_Category extends Walker {
foreach ( $_current_terms as $_current_term ) {
if ( $category->term_id == $_current_term->term_id ) {
$css_classes[] = 'current-cat';
$link = str_replace( '<a', '<a aria-current="page"', $link );
} elseif ( $category->term_id == $_current_term->parent ) {
$css_classes[] = 'current-cat-parent';
}

View File

@ -1735,18 +1735,19 @@ function get_the_post_type_description() {
* @return string HTML link content for archive.
*/
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
$text = wptexturize( $text );
$url = esc_url( $url );
$text = wptexturize( $text );
$url = esc_url( $url );
$aria_current = $selected ? ' aria-current="page"' : '';
if ( 'link' == $format ) {
if ( 'link' === $format ) {
$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
} elseif ( 'option' == $format ) {
} elseif ( 'option' === $format ) {
$selected_attr = $selected ? " selected='selected'" : '';
$link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n";
} elseif ( 'html' == $format ) {
$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
} elseif ( 'html' === $format ) {
$link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n";
} else { // custom
$link_html = "\t$before<a href='$url'>$text</a>$after\n";
$link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n";
}
/**

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-46162';
$wp_version = '5.3-alpha-46163';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -93,11 +93,16 @@ class WP_Widget_Recent_Posts extends WP_Widget {
<ul>
<?php foreach ( $r->posts as $recent_post ) : ?>
<?php
$post_title = get_the_title( $recent_post->ID );
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
$post_title = get_the_title( $recent_post->ID );
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
$aria_current = '';
if ( get_queried_object_id() === $recent_post->ID ) {
$aria_current = ' aria-current="page"';
}
?>
<li>
<a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title; ?></a>
<a href="<?php the_permalink( $recent_post->ID ); ?>"<?php echo $aria_current; ?>><?php echo $title; ?></a>
<?php if ( $show_date ) : ?>
<span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
<?php endif; ?>