Ticket #8058: 8058.patch

File 8058.patch, 4.3 KB (added by Viper007Bond, 4 years ago)

New functions + code cleanup

  • wp-includes/link-template.php

     
    10541054} 
    10551055 
    10561056/** 
    1057  * Display the next posts pages link. 
     1057 * Display or return the next posts pages link. 
    10581058 * 
    10591059 * @since 0.71 
    10601060 * 
    10611061 * @param int $max_page Optional. Max pages. 
     1062 * @param boolean $echo Optional. Echo or return; 
    10621063 */ 
    1063 function next_posts($max_page = 0) { 
    1064         echo clean_url(get_next_posts_page_link($max_page)); 
     1064function next_posts( $max_page = 0, $echo = true ) { 
     1065        $output = clean_url( get_next_posts_page_link( $max_page ) ); 
     1066 
     1067        if ( $echo ) 
     1068                echo $output; 
     1069        else 
     1070                return $output; 
    10651071} 
    10661072 
    10671073/** 
    1068  * Display the next posts pages link. 
     1074 * Return the next posts pages link. 
    10691075 * 
    1070  * @since 0.71 
     1076 * @since 2.7.0 
    10711077 * 
    10721078 * @param string $label Content for link text. 
    10731079 * @param int $max_page Optional. Max pages. 
     1080 * @return string 
    10741081 */ 
    1075 function next_posts_link($label='Next Page »', $max_page=0) { 
     1082function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) { 
    10761083        global $paged, $wp_query; 
    10771084        if ( !$max_page ) { 
    10781085                $max_page = $wp_query->max_num_pages; 
     
    10801087        if ( !$paged ) 
    10811088                $paged = 1; 
    10821089        $nextpage = intval($paged) + 1; 
    1083         if ( (! is_single()) && (empty($paged) || $nextpage <= $max_page) ) { 
    1084                 echo '<a href="'; 
    1085                 next_posts($max_page); 
     1090        $output = ''; 
     1091        if ( (!is_single() ) && ( empty($paged) || $nextpage <= $max_page) ) { 
    10861092                $attr = apply_filters( 'next_posts_link_attributes', '' ); 
    1087                 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>'; 
     1093                $output = '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>'; 
    10881094        } 
     1095        return $output; 
    10891096} 
    10901097 
    10911098/** 
     1099 * Display the next posts pages link. 
     1100 * 
     1101 * @since 0.71 
     1102 * @uses get_next_posts_link() 
     1103 * 
     1104 * @param string $label Content for link text. 
     1105 * @param int $max_page Optional. Max pages. 
     1106 */ 
     1107function next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) { 
     1108        echo get_next_posts_link( $label, $max_page ); 
     1109} 
     1110 
     1111/** 
    10921112 * Retrieve previous post pages link. 
    10931113 * 
    10941114 * Will only return string, if not on a single page or post. 
     
    11111131} 
    11121132 
    11131133/** 
    1114  * Display previous posts pages link. 
     1134 * Display or return the previous posts pages link. 
    11151135 * 
    11161136 * @since 0.71 
     1137 * 
     1138 * @param boolean $echo Optional. Echo or return; 
    11171139 */ 
    1118 function previous_posts() { 
    1119         echo clean_url(get_previous_posts_page_link()); 
     1140function previous_posts( $echo = true ) { 
     1141        $output = clean_url( get_previous_posts_page_link() ); 
     1142 
     1143        if ( $echo ) 
     1144                echo $output; 
     1145        else 
     1146                return $output; 
    11201147} 
    11211148 
    11221149/** 
    1123  * Display previous posts page link. 
     1150 * Return the previous posts pages link. 
    11241151 * 
    1125  * @since 0.71 
     1152 * @since 2.7.0 
    11261153 * 
    11271154 * @param string $label Optional. Previous page link text. 
     1155 * @return string 
    11281156 */ 
    1129 function previous_posts_link($label='&laquo; Previous Page') { 
     1157function get_previous_posts_link( $label = '&laquo; Previous Page' ) { 
    11301158        global $paged; 
    1131         if ( (!is_single())     && ($paged > 1) ) { 
    1132                 echo '<a href="'; 
    1133                 previous_posts(); 
     1159        $output = ''; 
     1160        if ( (!is_single() ) && ( $paged > 1) ) { 
    11341161                $attr = apply_filters( 'previous_posts_link_attributes', '' ); 
    1135                 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>'; 
     1162                $output = '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label ) .'</a>'; 
    11361163        } 
     1164        return $output; 
    11371165} 
    11381166 
    11391167/** 
     1168 * Display the previous posts page link. 
     1169 * 
     1170 * @since 0.71 
     1171 * @uses get_previous_posts_link() 
     1172 * 
     1173 * @param string $label Optional. Previous page link text. 
     1174 */ 
     1175function previous_posts_link( $label = '&laquo; Previous Page' ) { 
     1176        echo get_previous_posts_link( $label ); 
     1177} 
     1178 
     1179/** 
    11401180 * Display post pages link navigation for previous and next pages. 
    11411181 * 
    11421182 * @since 0.71 
     
    11451185 * @param string $prelabel Optional. Label for previous pages. 
    11461186 * @param string $nxtlabel Optional Label for next pages. 
    11471187 */ 
    1148 function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') { 
     1188function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) { 
    11491189        global $wp_query; 
    11501190        if ( !is_singular() ) { 
    11511191                $max_num_pages = $wp_query->max_num_pages;