Make WordPress Core

Ticket #24606: 24606.3.diff

File 24606.3.diff, 3.6 KB (added by obenland, 11 years ago)
  • src/wp-includes/general-template.php

     
    19831983 * It is possible to add query vars to the link by using the 'add_args' argument
    19841984 * and see {@link add_query_arg()} for more information.
    19851985 *
    1986  * The 'before_page_number' and 'after_page_number' arguments allow users to 
     1986 * The 'before_page_number' and 'after_page_number' arguments allow users to
    19871987 * augment the links themselves. Typically this might be to add context to the
    19881988 * numbered links so that screen reader users understand what the links are for.
    1989  * The text strings are added before and after the page number - within the 
     1989 * The text strings are added before and after the page number - within the
    19901990 * anchor tag.
    19911991 *
    19921992 * @since 2.1.0
     
    20282028        $page_links = array();
    20292029        $n = 0;
    20302030        $dots = false;
     2031        $base = str_replace( '%_%', $format, $base );
    20312032
    20322033        if ( $prev_next && $current && 1 < $current ) :
    2033                 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
    2034                 $link = str_replace('%#%', $current - 1, $link);
     2034                $link = str_replace( '%#%', $current - 1, $base );
    20352035                if ( $add_args )
    20362036                        $link = add_query_arg( $add_args, $link );
    20372037                $link .= $add_fragment;
     
    20432043                        $dots = true;
    20442044                else :
    20452045                        if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
    2046                                 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
    2047                                 $link = str_replace('%#%', $n, $link);
     2046                                $link = str_replace( '%#%', $n, $base );
    20482047                                if ( $add_args )
    20492048                                        $link = add_query_arg( $add_args, $link );
    20502049                                $link .= $add_fragment;
     
    20572056                endif;
    20582057        endfor;
    20592058        if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
    2060                 $link = str_replace('%_%', $format, $base);
    2061                 $link = str_replace('%#%', $current + 1, $link);
     2059                $link = str_replace( '%#%', $current + 1, $base );
    20622060                if ( $add_args )
    20632061                        $link = add_query_arg( $add_args, $link );
    20642062                $link .= $add_fragment;
  • tests/phpunit/tests/general/template.php

     
    2828                remove_filter( 'number_format_i18n', array( $this, 'increment_i18n_count' ) );
    2929        }
    3030
     31        /**
     32         * @ticket 24606
     33         */
     34        function test_paginate_links_base_value() {
     35
     36                // Current page: 2
     37                $links = paginate_links( array(
     38                        'current'  => 2,
     39                        'total'    => 5,
     40                        'end_size' => 1,
     41                        'mid_size' => 1,
     42                        'type'     => 'array',
     43                ) );
     44
     45                // It's supposed to link to page 1:
     46                $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => '?page=1' ) ), $links[0] );
     47                $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => '?page=1' ) ), $links[1] );
     48
     49                // It's not supposed to have an empty href.
     50                $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'prev page-numbers', 'href' => '' ) ), $links[0] );
     51                $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'page-numbers',      'href' => '' ) ), $links[1] );
     52
     53                // Current page: 1
     54                $links = paginate_links( array(
     55                        'current'  => 1,
     56                        'total'    => 5,
     57                        'end_size' => 1,
     58                        'mid_size' => 1,
     59                        'type'     => 'array',
     60                ) );
     61
     62                $this->assertTag( array( 'tag' => 'span', 'attributes' => array( 'class' => 'current' ) ), $links[0] );
     63                $this->assertTag( array( 'tag' => 'a',    'attributes' => array( 'href' => '?page=2'  ) ), $links[1] );
     64        }
    3165}