Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets: add aria-current attribute to links when on same page #13831

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions modules/widgets/authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<ul>';

while ( $r->have_posts() ) {
$r->the_post();
echo '<li><a href="' . get_permalink() . '">';

if ( get_the_title() ) {
echo get_the_title();
} else {
echo get_the_ID();
}

echo '</a></li>';
printf(
'<li><a href="%1$s" title="%2$s" %3$s>%4$s</a></li>',
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
esc_url( get_permalink() ),
esc_attr( wp_kses( get_the_title(), array() ) ),
( get_queried_object_id() === get_the_ID() ? ' aria-current="page"' : '' ),
esc_html( wp_kses( get_the_title(), array() ) )
);
}

echo '</ul>';
Expand Down
54 changes: 35 additions & 19 deletions modules/widgets/top-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,16 @@ function widget( $args, $instance ) {
*/
$filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );

?>
<a href="<?php echo esc_url( $filtered_permalink ); ?>" title="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" class="bump-view" data-bump-view="tp">
<img width="<?php echo absint( $width ); ?>" height="<?php echo absint( $height ); ?>" src="<?php echo esc_url( $post['image'] ); ?>" alt="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" data-pin-nopin="true" />
</a>
<?php
printf(
'<a href="%1$s" title="%2$s" class="bump-view" data-bump-view="tp"%3$s><img width="%4$d" height="%5$d" src="%6$s" alt="%2$s" data-pin-nopin="true"/></a>',
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 <li>.
*
Expand All @@ -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 );
?>
<a href="<?php echo esc_url( $filtered_permalink ); ?>" title="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" class="bump-view" data-bump-view="tp">
<img width="<?php echo absint( $width ); ?>" height="<?php echo absint( $height ); ?>" src="<?php echo esc_url( $post['image'] ); ?>" class='widgets-list-layout-blavatar' alt="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" data-pin-nopin="true" />
</a>
<div class="widgets-list-layout-links">
<a href="<?php echo esc_url( $filtered_permalink ); ?>" class="bump-view" data-bump-view="tp">
<?php echo esc_html( wp_kses( $post['title'], array() ) ); ?>

printf(
'<a href="%1$s" title="%2$s" class="bump-view" data-bump-view="tp"%3$s>
<img width="%4$d" height="%5$d" src="%6$s" alt="%2$s" data-pin-nopin="true" class="widgets-list-layout-blavatar"/>
</a>
</div>
<?php
<div class="widgets-list-layout-links">
<a href="%1$s" title="%2$s" class="bump-view" data-bump-view="tp"%3$s>%7$s</a>
</div>
',
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'] );
?>
Expand All @@ -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 );
?>
<a href="<?php echo esc_url( $filtered_permalink ); ?>" class="bump-view" data-bump-view="tp">
<?php echo esc_html( wp_kses( $post['title'], array() ) ); ?>
</a>
<?php

printf(
'<a href="%1$s" class="bump-view" data-bump-view="tp"%2$s>%3$s</a>',
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'] );
?>
Expand Down