Make WordPress Core

Changeset 41371


Ignore:
Timestamp:
09/11/2017 02:28:59 PM (7 years ago)
Author:
afercia
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r41232 r41371  
    32623262 *
    32633263 * @since 2.1.0
     3264 * @since 4.9.0 Added the `aria_current` argument.
    32643265 *
    32653266 * @global WP_Query   $wp_query
     
    32743275 *                                      `max_num_pages` or 1.
    32753276 *     @type int    $current            The current page number. Default is 'paged' query var or 1.
     3277 *     @type string $aria_current       The value for the aria-current attribute. Possible values are 'page',
     3278 *                                      'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
    32763279 *     @type bool   $show_all           Whether to show all pages. Default false.
    32773280 *     @type int    $end_size           How many numbers on either the start and the end list edges.
     
    33093312
    33103313    $defaults = array(
    3311         'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
    3312         'format' => $format, // ?page=%#% : %#% is replaced by the page number
    3313         'total' => $total,
    3314         'current' => $current,
    3315         'show_all' => false,
    3316         'prev_next' => true,
    3317         'prev_text' => __('« Previous'),
    3318         'next_text' => __('Next »'),
    3319         'end_size' => 1,
    3320         'mid_size' => 2,
    3321         'type' => 'plain',
    3322         'add_args' => array(), // array of query args to add
    3323         'add_fragment' => '',
     3314        'base'               => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
     3315        'format'             => $format, // ?page=%#% : %#% is replaced by the page number
     3316        'total'              => $total,
     3317        'current'            => $current,
     3318        'aria_current'       => 'page',
     3319        'show_all'           => false,
     3320        'prev_next'          => true,
     3321        'prev_text'          => __( '« Previous' ),
     3322        'next_text'          => __( 'Next »' ),
     3323        'end_size'           => 1,
     3324        'mid_size'           => 2,
     3325        'type'               => 'plain',
     3326        'add_args'           => array(), // array of query args to add
     3327        'add_fragment'       => '',
    33243328        'before_page_number' => '',
    3325         'after_page_number' => ''
     3329        'after_page_number'  => '',
    33263330    );
    33273331
     
    33873391    for ( $n = 1; $n <= $total; $n++ ) :
    33883392        if ( $n == $current ) :
    3389             $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
     3393            $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>";
    33903394            $dots = true;
    33913395        else :
  • trunk/tests/phpunit/tests/general/paginateLinks.php

    r34802 r41371  
    1717
    1818        $expected =<<<EXPECTED
    19 <span class='page-numbers current'>1</span>
     19<span aria-current='page' class='page-numbers current'>1</span>
    2020<a class='page-numbers' href='$page2'>2</a>
    2121<a class='page-numbers' href='$page3'>3</a>
     
    3535
    3636        $expected =<<<EXPECTED
    37 <span class='page-numbers current'>1</span>
     37<span aria-current='page' class='page-numbers current'>1</span>
    3838<a class='page-numbers' href='$page2'>2</a>
    3939<a class='page-numbers' href='$page3'>3</a>
     
    5555        $expected =<<<EXPECTED
    5656<a class='page-numbers' href='$home'>1</a>
    57 <span class='page-numbers current'>2</span>
     57<span aria-current='page' class='page-numbers current'>2</span>
    5858<a class='page-numbers' href='$page3'>3</a>
    5959<a class='page-numbers' href='$page4'>4</a>
     
    7575<a class="prev page-numbers" href="$home">&laquo; Previous</a>
    7676<a class='page-numbers' href='$home'>1</a>
    77 <span class='page-numbers current'>2</span>
     77<span aria-current='page' class='page-numbers current'>2</span>
    7878<a class='page-numbers' href='$page3'>3</a>
    7979<a class='page-numbers' href='$page4'>4</a>
     
    300300        ) );
    301301
    302         $this->assertContains( "<span class='page-numbers current'>3</span>", $links );
     302        $this->assertContains( "<span aria-current='page' class='page-numbers current'>3</span>", $links );
    303303    }
    304304
Note: See TracChangeset for help on using the changeset viewer.