Make WordPress Core


Ignore:
Timestamp:
05/14/2014 10:28:08 PM (10 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in paginate_links(). Adds unit tests. Moves tests/general/template.php (which only had one method) to tests/general/paginateLinks.php.

See #22400.

File:
1 edited

Legend:

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

    r28379 r28397  
    24482448
    24492449    $args = wp_parse_args( $args, $defaults );
    2450     extract($args, EXTR_SKIP);
    24512450
    24522451    // Who knows what else people pass in $args
    2453     $total = (int) $total;
    2454     if ( $total < 2 )
     2452    $total = (int) $args['total'];
     2453    if ( $total < 2 ) {
    24552454        return;
    2456     $current  = (int) $current;
    2457     $end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default.
    2458     $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
    2459     $add_args = is_array($add_args) ? $add_args : false;
     2455    }
     2456    $current  = (int) $args['current'];
     2457    $end_size = (int) $args['end_size']; // Out of bounds?  Make it the default.
     2458    if ( $end_size < 1 ) {
     2459        $end_size = 1;
     2460    }
     2461    $mid_size = (int) $args['mid_size'];
     2462    if ( $mid_size < 0 ) {
     2463        $mid_size = 2;
     2464    }
     2465    $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false;
    24602466    $r = '';
    24612467    $page_links = array();
    24622468    $dots = false;
    24632469
    2464     if ( $prev_next && $current && 1 < $current ) :
    2465         $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
    2466         $link = str_replace('%#%', $current - 1, $link);
     2470    if ( $args['prev_next'] && $current && 1 < $current ) :
     2471        $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
     2472        $link = str_replace( '%#%', $current - 1, $link );
    24672473        if ( $add_args )
    24682474            $link = add_query_arg( $add_args, $link );
    2469         $link .= $add_fragment;
     2475        $link .= $args['add_fragment'];
    24702476
    24712477        /**
     
    24762482         * @param string $link The paginated link URL.
    24772483         */
    2478         $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
     2484        $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
    24792485    endif;
    24802486    for ( $n = 1; $n <= $total; $n++ ) :
    24812487        if ( $n == $current ) :
    2482             $page_links[] = "<span class='page-numbers current'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</span>";
     2488            $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
    24832489            $dots = true;
    24842490        else :
    2485             if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
    2486                 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
    2487                 $link = str_replace('%#%', $n, $link);
     2491            if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
     2492                $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
     2493                $link = str_replace( '%#%', $n, $link );
    24882494                if ( $add_args )
    24892495                    $link = add_query_arg( $add_args, $link );
    2490                 $link .= $add_fragment;
     2496                $link .= $args['add_fragment'];
    24912497
    24922498                /** This filter is documented in wp-includes/general-template.php */
    2493                 $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $before_page_number . number_format_i18n( $n ) . $after_page_number . "</a>";
     2499                $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>";
    24942500                $dots = true;
    2495             elseif ( $dots && !$show_all ) :
     2501            elseif ( $dots && ! $args['show_all'] ) :
    24962502                $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
    24972503                $dots = false;
     
    24992505        endif;
    25002506    endfor;
    2501     if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
    2502         $link = str_replace('%_%', $format, $base);
    2503         $link = str_replace('%#%', $current + 1, $link);
     2507    if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
     2508        $link = str_replace( '%_%', $args['format'], $args['base'] );
     2509        $link = str_replace( '%#%', $current + 1, $link );
    25042510        if ( $add_args )
    25052511            $link = add_query_arg( $add_args, $link );
    2506         $link .= $add_fragment;
     2512        $link .= $args['add_fragment'];
    25072513
    25082514        /** This filter is documented in wp-includes/general-template.php */
    2509         $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
     2515        $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
    25102516    endif;
    2511     switch ( $type ) {
     2517    switch ( $args['type'] ) {
    25122518        case 'array' :
    25132519            return $page_links;
Note: See TracChangeset for help on using the changeset viewer.