Make WordPress Core

Ticket #7231: 7231.2.patch

File 7231.2.patch, 8.6 KB (added by seanchayes, 8 years ago)
  • src/wp-includes/post-template.php

     
    776776 * @param string|array $args {
    777777 *     Optional. Array or string of default arguments.
    778778 *
    779  *     @type string       $before           HTML or text to prepend to each link. Default is `<p> Pages:`.
    780  *     @type string       $after            HTML or text to append to each link. Default is `</p>`.
    781  *     @type string       $link_before      HTML or text to prepend to each link, inside the `<a>` tag.
    782  *                                          Also prepended to the current item, which is not linked. Default empty.
    783  *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
    784  *                                          Also appended to the current item, which is not linked. Default empty.
    785  *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
    786  *                                          and next. Default is 'number'.
    787  *     @type string       $separator        Text between pagination links. Default is ' '.
    788  *     @type string       $nextpagelink     Link text for the next page link, if available. Default is 'Next Page'.
    789  *     @type string       $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'.
    790  *     @type string       $pagelink         Format string for page numbers. The % in the parameter string will be
    791  *                                          replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc.
    792  *                                          Defaults to '%', just the page number.
    793  *     @type int|bool     $echo             Whether to echo or not. Accepts 1|true or 0|false. Default 1|true.
     779 *     @type string       $before            HTML or text to prepend to each link. Default is `<p> Pages:`.
     780 *     @type string       $after             HTML or text to append to each link. Default is `</p>`.
     781 *     @type string       $link_before       HTML or text to prepend to each link, inside the `<a>` tag.
     782 *                                           Also prepended to the current item, which is not linked. Default empty.
     783 *     @type string       $link_after        HTML or text to append to each Pages link inside the `<a>` tag.
     784 *                                           Also appended to the current item, which is not linked. Default empty.
     785 *     @type string       $next_or_number    Indicates whether page numbers should be used. Valid values are number
     786 *                                           and next. Default is 'number'.
     787 *     @type string       $separator         Text between pagination links. Default is ' '.
     788 *     @type string       $nextpagelink      Link text for the next page link, if available. Default is 'Next Page'.
     789 *     @type string       $nextpageclass     Class for link text for the next page link, if available. Default is 'next'.
     790 *     @type string       $previouspagelink  Link text for the previous page link, if available. Default is 'Previous Page'.
     791 *     @type string       $previouspageclass Class for link text for the previous page link, if available. Default is 'previous'.
     792 *     @type string       $pagelink          Format string for page numbers. The % in the parameter string will be
     793 *                                           replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc.
     794 *                                           Defaults to '%', just the page number.
     795 *     @type int|bool     $echo              Whether to echo or not. Accepts 1|true or 0|false. Default 1|true.
    794796 * }
    795797 * @return string Formatted output in HTML.
    796798 */
     
    805807                'next_or_number'   => 'number',
    806808                'separator'        => ' ',
    807809                'nextpagelink'     => __( 'Next page' ),
     810                'nextpageclass'    => 'next',
    808811                'previouspagelink' => __( 'Previous page' ),
     812                'previouspageclass'=> 'previous',
    809813                'pagelink'         => '%',
    810814                'echo'             => 1
    811815        );
     
    823827
    824828        $output = '';
    825829        if ( $multipage ) {
     830                $output .= $r['before'];
    826831                if ( 'number' == $r['next_or_number'] ) {
    827                         $output .= $r['before'];
    828                         for ( $i = 1; $i <= $numpages; $i++ ) {
    829                                 $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
    830                                 if ( $i != $page || ! $more && 1 == $page ) {
    831                                         $link = _wp_link_page( $i ) . $link . '</a>';
     832                        $output .= _wp_link_pages_numbers( $r );
     833                } elseif ( 'next_and_number' == $r['next_or_number'] ) {
     834                        $prev = $page - 1;
     835                        if ( $prev > 0 ) {
     836                                $link = _wp_link_page( $prev, 'previous' ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
     837
     838                                /** This filter is documented in wp-includes/post-template.php */
     839                                $output .= apply_filters( 'wp_link_pages_link', $link, $prev );
     840                        }
     841                        $output .= _wp_link_pages_numbers( $r );
     842                        $next = $page + 1;
     843                        if ( $next <= $numpages ) {
     844                                if ( $prev ) {
     845                                        $output .= $r['separator'];
    832846                                }
    833                                 /**
    834                                  * Filter the HTML output of individual page number links.
    835                                  *
    836                                  * @since 3.6.0
    837                                  *
    838                                  * @param string $link The page number HTML output.
    839                                  * @param int    $i    Page number for paginated posts' page links.
    840                                  */
    841                                 $link = apply_filters( 'wp_link_pages_link', $link, $i );
     847                                $link = _wp_link_page( $next, 'next' ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
    842848
    843                                 // Use the custom links separator beginning with the second link.
    844                                 $output .= ( 1 === $i ) ? ' ' : $r['separator'];
    845                                 $output .= $link;
     849                                /** This filter is documented in wp-includes/post-template.php */
     850                                $output .= apply_filters( 'wp_link_pages_link', $link, $next );
    846851                        }
    847                         $output .= $r['after'];
    848852                } elseif ( $more ) {
    849                         $output .= $r['before'];
    850853                        $prev = $page - 1;
    851854                        if ( $prev > 0 ) {
    852                                 $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
     855                                $link = _wp_link_page( $prev, 'previous' ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
    853856
    854857                                /** This filter is documented in wp-includes/post-template.php */
    855858                                $output .= apply_filters( 'wp_link_pages_link', $link, $prev );
     
    859862                                if ( $prev ) {
    860863                                        $output .= $r['separator'];
    861864                                }
    862                                 $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
     865                                $link = _wp_link_page( $next, 'next' ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
    863866
    864867                                /** This filter is documented in wp-includes/post-template.php */
    865868                                $output .= apply_filters( 'wp_link_pages_link', $link, $next );
    866869                        }
    867                         $output .= $r['after'];
    868870                }
     871                $output .= $r['after'];
     872
    869873        }
    870874
    871875        /**
     
    893897 * @global WP_Rewrite $wp_rewrite
    894898 *
    895899 * @param int $i Page number.
     900 * @param string $class Class to apply to link - typically related to specifying 'previous' or 'next'
    896901 * @return string Link.
    897902 */
    898 function _wp_link_page( $i ) {
     903function _wp_link_page( $i, $class = '' ) {
    899904        global $wp_rewrite;
    900905        $post = get_post();
    901906        $query_args = array();
     
    921926                $url = get_preview_post_link( $post, $query_args, $url );
    922927        }
    923928
    924         return '<a href="' . esc_url( $url ) . '">';
     929        if ( '' != $class ) {
     930                $class = ' class="' . esc_attr( $class ) . '"';
     931        }
     932        return '<a href="' . esc_url( $url ) .'"' . $class . '>';
    925933}
    926934
     935/**
     936 * Creates and returns number based page links for paginated posts
     937 * (i.e. includes the <!--nextpage-->. Quicktag one or more times). This tag must be within The Loop.
     938 *
     939 * Helper function for wp_link_pages().
     940 * @since 4.4
     941 * @access private
     942 *
     943 * @global int $page
     944 * @global int $numpages
     945 * @global int $more
     946 *
     947 * @param $params
     948 *
     949 * @return string
     950 */
     951function _wp_link_pages_numbers( $params ) {
     952        global $page, $numpages, $more;
     953
     954        $output = '';
     955        for ( $i = 1; $i <= $numpages; $i++ ) {
     956                $link = $params['link_before'] . str_replace( '%', $i, $params['pagelink'] ) . $params['link_after'];
     957                if ( $i != $page || ! $more && 1 == $page ) {
     958                        $link = _wp_link_page( $i ) . $link . '</a>';
     959                }
     960                /**
     961                 * Filter the HTML output of individual page number links.
     962                 *
     963                 * @since 3.6.0
     964                 *
     965                 * @param string $link The page number HTML output.
     966                 * @param int    $i    Page number for paginated posts' page links.
     967                 */
     968                $link = apply_filters( 'wp_link_pages_link', $link, $i );
     969
     970                // Use the custom links separator beginning with the second link.
     971                $output .= ( 1 === $i ) ? ' ' : $params['separator'];
     972                $output .= $link;
     973        }
     974        return $output;
     975}
     976
    927977//
    928978// Post-meta: Custom per-post fields.
    929979//