Allow usage of `aria-current` in `paginate_links()`.
The `aria-current` attribute is a simple, effective way to help assistive technology users orientate themselves within a list of items. Props GrahamArmfield, palmiak. Fixes #40833. git-svn-id: https://develop.svn.wordpress.org/trunk@41371 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
71aaf1fa4a
commit
34df35a414
|
@ -3261,6 +3261,7 @@ function language_attributes( $doctype = 'html' ) {
|
||||||
* anchor tag.
|
* anchor tag.
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
|
* @since 4.9.0 Added the `aria_current` argument.
|
||||||
*
|
*
|
||||||
* @global WP_Query $wp_query
|
* @global WP_Query $wp_query
|
||||||
* @global WP_Rewrite $wp_rewrite
|
* @global WP_Rewrite $wp_rewrite
|
||||||
|
@ -3273,6 +3274,8 @@ function language_attributes( $doctype = 'html' ) {
|
||||||
* @type int $total The total amount of pages. Default is the value WP_Query's
|
* @type int $total The total amount of pages. Default is the value WP_Query's
|
||||||
* `max_num_pages` or 1.
|
* `max_num_pages` or 1.
|
||||||
* @type int $current The current page number. Default is 'paged' query var or 1.
|
* @type int $current The current page number. Default is 'paged' query var or 1.
|
||||||
|
* @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 bool $show_all Whether to show all pages. Default false.
|
* @type bool $show_all Whether to show all pages. Default false.
|
||||||
* @type int $end_size How many numbers on either the start and the end list edges.
|
* @type int $end_size How many numbers on either the start and the end list edges.
|
||||||
* Default 1.
|
* Default 1.
|
||||||
|
@ -3308,21 +3311,22 @@ function paginate_links( $args = '' ) {
|
||||||
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
|
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
|
'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
|
||||||
'format' => $format, // ?page=%#% : %#% is replaced by the page number
|
'format' => $format, // ?page=%#% : %#% is replaced by the page number
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'current' => $current,
|
'current' => $current,
|
||||||
'show_all' => false,
|
'aria_current' => 'page',
|
||||||
'prev_next' => true,
|
'show_all' => false,
|
||||||
'prev_text' => __('« Previous'),
|
'prev_next' => true,
|
||||||
'next_text' => __('Next »'),
|
'prev_text' => __( '« Previous' ),
|
||||||
'end_size' => 1,
|
'next_text' => __( 'Next »' ),
|
||||||
'mid_size' => 2,
|
'end_size' => 1,
|
||||||
'type' => 'plain',
|
'mid_size' => 2,
|
||||||
'add_args' => array(), // array of query args to add
|
'type' => 'plain',
|
||||||
'add_fragment' => '',
|
'add_args' => array(), // array of query args to add
|
||||||
|
'add_fragment' => '',
|
||||||
'before_page_number' => '',
|
'before_page_number' => '',
|
||||||
'after_page_number' => ''
|
'after_page_number' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
$args = wp_parse_args( $args, $defaults );
|
$args = wp_parse_args( $args, $defaults );
|
||||||
|
@ -3386,7 +3390,7 @@ function paginate_links( $args = '' ) {
|
||||||
endif;
|
endif;
|
||||||
for ( $n = 1; $n <= $total; $n++ ) :
|
for ( $n = 1; $n <= $total; $n++ ) :
|
||||||
if ( $n == $current ) :
|
if ( $n == $current ) :
|
||||||
$page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
|
$page_links[] = "<span aria-current='" . esc_attr( $args['aria_current'] ) . "' class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
|
||||||
$dots = true;
|
$dots = true;
|
||||||
else :
|
else :
|
||||||
if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
|
if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Tests_Paginate_Links extends WP_UnitTestCase {
|
||||||
$page50 = get_pagenum_link( 50 );
|
$page50 = get_pagenum_link( 50 );
|
||||||
|
|
||||||
$expected =<<<EXPECTED
|
$expected =<<<EXPECTED
|
||||||
<span class='page-numbers current'>1</span>
|
<span aria-current='page' class='page-numbers current'>1</span>
|
||||||
<a class='page-numbers' href='$page2'>2</a>
|
<a class='page-numbers' href='$page2'>2</a>
|
||||||
<a class='page-numbers' href='$page3'>3</a>
|
<a class='page-numbers' href='$page3'>3</a>
|
||||||
<span class="page-numbers dots">…</span>
|
<span class="page-numbers dots">…</span>
|
||||||
|
@ -34,7 +34,7 @@ EXPECTED;
|
||||||
$page50 = home_url( '/page/50/' );
|
$page50 = home_url( '/page/50/' );
|
||||||
|
|
||||||
$expected =<<<EXPECTED
|
$expected =<<<EXPECTED
|
||||||
<span class='page-numbers current'>1</span>
|
<span aria-current='page' class='page-numbers current'>1</span>
|
||||||
<a class='page-numbers' href='$page2'>2</a>
|
<a class='page-numbers' href='$page2'>2</a>
|
||||||
<a class='page-numbers' href='$page3'>3</a>
|
<a class='page-numbers' href='$page3'>3</a>
|
||||||
<span class="page-numbers dots">…</span>
|
<span class="page-numbers dots">…</span>
|
||||||
|
@ -54,7 +54,7 @@ EXPECTED;
|
||||||
|
|
||||||
$expected =<<<EXPECTED
|
$expected =<<<EXPECTED
|
||||||
<a class='page-numbers' href='$home'>1</a>
|
<a class='page-numbers' href='$home'>1</a>
|
||||||
<span class='page-numbers current'>2</span>
|
<span aria-current='page' class='page-numbers current'>2</span>
|
||||||
<a class='page-numbers' href='$page3'>3</a>
|
<a class='page-numbers' href='$page3'>3</a>
|
||||||
<a class='page-numbers' href='$page4'>4</a>
|
<a class='page-numbers' href='$page4'>4</a>
|
||||||
<span class="page-numbers dots">…</span>
|
<span class="page-numbers dots">…</span>
|
||||||
|
@ -74,7 +74,7 @@ EXPECTED;
|
||||||
$expected =<<<EXPECTED
|
$expected =<<<EXPECTED
|
||||||
<a class="prev page-numbers" href="$home">« Previous</a>
|
<a class="prev page-numbers" href="$home">« Previous</a>
|
||||||
<a class='page-numbers' href='$home'>1</a>
|
<a class='page-numbers' href='$home'>1</a>
|
||||||
<span class='page-numbers current'>2</span>
|
<span aria-current='page' class='page-numbers current'>2</span>
|
||||||
<a class='page-numbers' href='$page3'>3</a>
|
<a class='page-numbers' href='$page3'>3</a>
|
||||||
<a class='page-numbers' href='$page4'>4</a>
|
<a class='page-numbers' href='$page4'>4</a>
|
||||||
<span class="page-numbers dots">…</span>
|
<span class="page-numbers dots">…</span>
|
||||||
|
@ -299,7 +299,7 @@ EXPECTED;
|
||||||
'type' => 'array',
|
'type' => 'array',
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$this->assertContains( "<span class='page-numbers current'>3</span>", $links );
|
$this->assertContains( "<span aria-current='page' class='page-numbers current'>3</span>", $links );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue