Make WordPress Core

Changeset 28398


Ignore:
Timestamp:
05/15/2014 12:43:40 AM (12 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in wp_link_pages().

Adds unit tests to a new file: tests/post/template.php.
There were previously no unit tests for wp_link_pages().

See #22400.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r28383 r28398  
    740740        );
    741741
    742         $r = wp_parse_args( $args, $defaults );
     742        $params = wp_parse_args( $args, $defaults );
    743743
    744744        /**
    … …  
    747747         * @since 3.0.0
    748748         *
    749          * @param array $r An array of arguments for page links for paginated posts.
    750          */
    751         $r = apply_filters( 'wp_link_pages_args', $r );
    752         extract( $r, EXTR_SKIP );
     749         * @param array $params An array of arguments for page links for paginated posts.
     750         */
     751        $r = apply_filters( 'wp_link_pages_args', $params );
    753752
    754753        global $page, $numpages, $multipage, $more;
    … …  
    756755        $output = '';
    757756        if ( $multipage ) {
    758                 if ( 'number' == $next_or_number ) {
    759                         $output .= $before;
     757                if ( 'number' == $r['next_or_number'] ) {
     758                        $output .= $r['before'];
    760759                        for ( $i = 1; $i <= $numpages; $i++ ) {
    761                                 $link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after;
    762                                 if ( $i != $page || ! $more && 1 == $page )
     760                                $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
     761                                if ( $i != $page || ! $more && 1 == $page ) {
    763762                                        $link = _wp_link_page( $i ) . $link . '</a>';
    764 
     763                                }
    765764                                /**
    766765                                 * Filter the HTML output of individual page number links.
    … …  
    772771                                 */
    773772                                $link = apply_filters( 'wp_link_pages_link', $link, $i );
    774                                 $output .= $separator . $link;
     773                                $output .= $r['separator'] . $link;
    775774                        }
    776                         $output .= $after;
     775                        $output .= $r['after'];
    777776                } elseif ( $more ) {
    778                         $output .= $before;
    779                         $i = $page - 1;
    780                         if ( $i ) {
    781                                 $link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . '</a>';
     777                        $output .= $r['before'];
     778                        $prev = $page - 1;
     779                        if ( $prev ) {
     780                                $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
    782781
    783782                                /** This filter is documented in wp-includes/post-template.php */
    784                                 $link = apply_filters( 'wp_link_pages_link', $link, $i );
    785                                 $output .= $separator . $link;
     783                                $link = apply_filters( 'wp_link_pages_link', $link, $prev );
     784                                $output .= $r['separator'] . $link;
    786785                        }
    787                         $i = $page + 1;
    788                         if ( $i <= $numpages ) {
    789                                 $link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . '</a>';
     786                        $next = $page + 1;
     787                        if ( $next <= $numpages ) {
     788                                $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
    790789
    791790                                /** This filter is documented in wp-includes/post-template.php */
    792                                 $link = apply_filters( 'wp_link_pages_link', $link, $i );
    793                                 $output .= $separator . $link;
     791                                $link = apply_filters( 'wp_link_pages_link', $link, $next );
     792                                $output .= $r['separator'] . $link;
    794793                        }
    795                         $output .= $after;
     794                        $output .= $r['after'];
    796795                }
    797796        }
    … …  
    802801         * @since 3.6.0
    803802         *
    804          * @param string $output HTML output of paginated posts' page links.
     803         * @param string $html HTML output of paginated posts' page links.
    805804         * @param array  $args   An array of arguments.
    806805         */
    807         $output = apply_filters( 'wp_link_pages', $output, $args );
    808 
    809         if ( $echo )
    810                 echo $output;
    811 
    812         return $output;
     806        $html = apply_filters( 'wp_link_pages', $output, $args );
     807
     808        if ( $r['echo'] ) {
     809                echo $html;
     810        }
     811        return $html;
    813812}
    814813
Note: See TracChangeset for help on using the changeset viewer.