WordPress.org

Make WordPress Core

Ticket #13489: 13489.patch

File 13489.patch, 2.8 KB (added by GaryJ, 3 years ago)

Adds get_adjacent_posts_link() as a copy of current adjacent_post_link() but as a return. Makes adjacent_post_link() into an echo of get_adjacent_post_link().

  • wp-includes/link-template.php

     
    14381438 * @param string $excluded_categories Optional. Excluded categories IDs. 
    14391439 * @param bool $previous Optional, default is true. Whether display link to previous post. 
    14401440 */ 
    1441 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { 
     1441function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) { 
     1442        echo get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_categories, $previous ); 
     1443} 
     1444 
     1445/** 
     1446 * Display adjacent post link. 
     1447 * 
     1448 * Can be either next post link or previous. 
     1449 * 
     1450 * @since 3.2 
     1451 * 
     1452 * @param string $format Link anchor format. 
     1453 * @param string $link Link permalink format. 
     1454 * @param bool $in_same_cat Optional. Whether link should be in same category. 
     1455 * @param string $excluded_categories Optional. Excluded categories IDs. 
     1456 * @param bool $previous Optional, default is true. Whether display link to previous post. 
     1457 */ 
     1458function get_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) { 
    14421459        if ( $previous && is_attachment() ) 
    1443                 $post = & get_post($GLOBALS['post']->post_parent); 
     1460                $post = & get_post( $GLOBALS['post']->post_parent ); 
    14441461        else 
    1445                 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); 
     1462                $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous ); 
    14461463 
    1447         if ( !$post ) 
     1464        if ( ! $post ) 
    14481465                return; 
    14491466 
    14501467        $title = $post->post_title; 
    14511468 
    1452         if ( empty($post->post_title) ) 
    1453                 $title = $previous ? __('Previous Post') : __('Next Post'); 
     1469        if ( empty( $post->post_title ) ) 
     1470                $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); 
    14541471 
    1455         $title = apply_filters('the_title', $title, $post->ID); 
    1456         $date = mysql2date(get_option('date_format'), $post->post_date); 
     1472        $title = apply_filters( 'the_title', $title, $post->ID ); 
     1473        $date = mysql2date( get_option( 'date_format' ), $post->post_date ); 
    14571474        $rel = $previous ? 'prev' : 'next'; 
    14581475 
    1459         $string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">'; 
    1460         $link = str_replace('%title', $title, $link); 
    1461         $link = str_replace('%date', $date, $link); 
     1476        $string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">'; 
     1477        $link = str_replace( '%title', $title, $link ); 
     1478        $link = str_replace( '%date', $date, $link ); 
    14621479        $link = $string . $link . '</a>'; 
    14631480 
    1464         $format = str_replace('%link', $link, $format); 
     1481        $format = str_replace( '%link', $link, $format ); 
    14651482 
    14661483        $adjacent = $previous ? 'previous' : 'next'; 
    1467         echo apply_filters( "{$adjacent}_post_link", $format, $link ); 
     1484        return apply_filters( "{$adjacent}_post_link", $format, $link ); 
    14681485} 
    14691486 
    14701487/**