From 3e38b0b53a2e898e5905529d43c2182ced405084 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 24 Oct 2019 16:16:13 +0200 Subject: [PATCH 1/2] Widgets: add aria-current attribute to links when on same page This brings our 2 widgets currently outputting internal links (Authors and Top Posts) up to date with Core's accessibility improvements: https://core.trac.wordpress.org/ticket/47094 --- modules/widgets/authors.php | 18 ++++++------ modules/widgets/top-posts.php | 54 +++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/modules/widgets/authors.php b/modules/widgets/authors.php index f365c3b1a0eff..176cfb841d4de 100644 --- a/modules/widgets/authors.php +++ b/modules/widgets/authors.php @@ -172,22 +172,20 @@ public function widget( $args, $instance ) { continue; } - // Display a short list of recent posts for this author - + // Display a short list of recent posts for this author. if ( $r->have_posts() ) { echo ''; diff --git a/modules/widgets/top-posts.php b/modules/widgets/top-posts.php index 442dddd7b0be8..9a80439235298 100644 --- a/modules/widgets/top-posts.php +++ b/modules/widgets/top-posts.php @@ -406,11 +406,16 @@ function widget( $args, $instance ) { */ $filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post ); - ?> - - <?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?> - - %2$s', + esc_url( $filtered_permalink ), + esc_attr( wp_kses( $post['title'], array() ) ), + ( get_queried_object_id() === $post['post_id'] ? ' aria-current="page"' : '' ), + absint( $width ), + absint( $height ), + esc_url( $post['image'] ) + ); + /** * Fires after each Top Post result, inside
  • . * @@ -437,16 +442,24 @@ function widget( $args, $instance ) { /** This filter is documented in modules/widgets/top-posts.php */ $filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post ); - ?> - - <?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?> - - - + %7$s + + ', + esc_url( $filtered_permalink ), + esc_attr( wp_kses( $post['title'], array() ) ), + ( get_queried_object_id() === $post['post_id'] ? ' aria-current="page"' : '' ), + absint( $width ), + absint( $height ), + esc_url( $post['image'] ), + esc_html( wp_kses( $post['title'], array() ) ) + ); + /** This action is documented in modules/widgets/top-posts.php */ do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] ); ?> @@ -467,11 +480,14 @@ function widget( $args, $instance ) { /** This filter is documented in modules/widgets/top-posts.php */ $filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post ); - ?> - - - - %3$s', + esc_url( $filtered_permalink ), + ( get_queried_object_id() === $post['post_id'] ? ' aria-current="page"' : '' ), + esc_html( wp_kses( $post['title'], array() ) ) + ); + /** This action is documented in modules/widgets/top-posts.php */ do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] ); ?> From 9add7527b7fc93b5d81ef6ac8ab0b016dee259b7 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 25 Oct 2019 16:48:48 -0500 Subject: [PATCH 2/2] Update modules/widgets/authors.php --- modules/widgets/authors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/widgets/authors.php b/modules/widgets/authors.php index 176cfb841d4de..741856d84ccc1 100644 --- a/modules/widgets/authors.php +++ b/modules/widgets/authors.php @@ -180,7 +180,7 @@ public function widget( $args, $instance ) { $r->the_post(); printf( - '
  • %4$s
  • ', + '
  • %4$s
  • ', esc_url( get_permalink() ), esc_attr( wp_kses( get_the_title(), array() ) ), ( get_queried_object_id() === get_the_ID() ? ' aria-current="page"' : '' ),