From 1258d1d9d2c7bef7c18b4e3420219cfa716d0aca Mon Sep 17 00:00:00 2001
From: Andrea Fercia
Date: Fri, 12 Jan 2018 20:16:56 +0000
Subject: [PATCH] Accessibility: use `aria-current` for the paginated post
links output by `wp_link_pages()`.
Continues the introduction in core of the aria-current attribute after [41683], [41359], and [41371].
- changes the `wp_link_pages()` (see the `nextpage` quicktag) output to use an `aria-current` attribute on the current item
- adds `post-nav-links` and `post-page-numbers` CSS classes to help themes style these links
- updates the related tests
Props antonioeatgoat, alexstine.
Fixes #41859.
git-svn-id: https://develop.svn.wordpress.org/trunk@42440 602fd350-edb4-49c9-b593-d223f7449a82
---
src/wp-includes/post-template.php | 10 ++++++++--
tests/phpunit/tests/post/template.php | 14 +++++++-------
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php
index 36dec909ac..e49cdd2164 100644
--- a/src/wp-includes/post-template.php
+++ b/src/wp-includes/post-template.php
@@ -862,6 +862,7 @@ function post_password_required( $post = null ) {
* Quicktag one or more times). This tag must be within The Loop.
*
* @since 1.2.0
+ * @since 5.0.0 Added the `aria_current` argument.
*
* @global int $page
* @global int $numpages
@@ -877,6 +878,8 @@ function post_password_required( $post = null ) {
* Also prepended to the current item, which is not linked. Default empty.
* @type string $link_after HTML or text to append to each Pages link inside the `` tag.
* Also appended to the current item, which is not linked. Default empty.
+ * @type string $aria_current The value for the aria-current attribute. Possible values are 'page',
+ * 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
* @type string $next_or_number Indicates whether page numbers should be used. Valid values are number
* and next. Default is 'number'.
* @type string $separator Text between pagination links. Default is ' '.
@@ -893,10 +896,11 @@ function wp_link_pages( $args = '' ) {
global $page, $numpages, $multipage, $more;
$defaults = array(
- 'before' => '' . __( 'Pages:' ),
+ 'before' => '
' . __( 'Pages:' ),
'after' => '
',
'link_before' => '',
'link_after' => '',
+ 'aria_current' => 'page',
'next_or_number' => 'number',
'separator' => ' ',
'nextpagelink' => __( 'Next page' ),
@@ -924,6 +928,8 @@ function wp_link_pages( $args = '' ) {
$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
if ( $i != $page || ! $more && 1 == $page ) {
$link = _wp_link_page( $i ) . $link . '';
+ } elseif ( $i === $page ) {
+ $link = '' . $link . '';
}
/**
* Filters the HTML output of individual page number links.
@@ -1017,7 +1023,7 @@ function _wp_link_page( $i ) {
$url = get_preview_post_link( $post, $query_args, $url );
}
- return '';
+ return '';
}
//
diff --git a/tests/phpunit/tests/post/template.php b/tests/phpunit/tests/post/template.php
index 4910216b00..9be2fb63d2 100644
--- a/tests/phpunit/tests/post/template.php
+++ b/tests/phpunit/tests/post/template.php
@@ -14,16 +14,16 @@ class Tests_Post_Template extends WP_UnitTestCase {
setup_postdata( get_post( $post_id ) );
- $permalink = sprintf( '', get_permalink() );
+ $permalink = sprintf( '', get_permalink() );
$page2 = _wp_link_page( 2 );
$page3 = _wp_link_page( 3 );
- $expected = "Pages: 1 {$page2}2
{$page3}3
";
+ $expected = 'Pages: 1 ' . $page2 . '2 ' . $page3 . '3
';
$output = wp_link_pages( array( 'echo' => 0 ) );
$this->assertEquals( $expected, $output );
- $before_after = " 1 {$page2}2 {$page3}3";
+ $before_after = " 1 {$page2}2 {$page3}3";
$output = wp_link_pages(
array(
'echo' => 0,
@@ -34,7 +34,7 @@ class Tests_Post_Template extends WP_UnitTestCase {
$this->assertEquals( $before_after, $output );
- $separator = " 1{$page2}2{$page3}3";
+ $separator = " 1{$page2}2{$page3}3";
$output = wp_link_pages(
array(
'echo' => 0,
@@ -46,7 +46,7 @@ class Tests_Post_Template extends WP_UnitTestCase {
$this->assertEquals( $separator, $output );
- $link = " 1{$page2}2{$page3}3";
+ $link = " 1{$page2}2{$page3}3";
$output = wp_link_pages(
array(
'echo' => 0,
@@ -107,7 +107,7 @@ class Tests_Post_Template extends WP_UnitTestCase {
$this->assertEquals( $next_prev_link, $output );
$GLOBALS['page'] = 1;
- $separator = "Pages: 1 | {$page2}2 | {$page3}3
";
+ $separator = "Pages: 1 | {$page2}2 | {$page3}3
";
$output = wp_link_pages(
array(
'echo' => 0,
@@ -117,7 +117,7 @@ class Tests_Post_Template extends WP_UnitTestCase {
$this->assertEquals( $separator, $output );
- $pagelink = " Page 1 | {$page2}Page 2 | {$page3}Page 3";
+ $pagelink = " Page 1 | {$page2}Page 2 | {$page3}Page 3";
$output = wp_link_pages(
array(
'echo' => 0,