WordPress.org

Make WordPress Core

Changeset 21802


Ignore:
Timestamp:
09/10/2012 09:36:06 PM (6 years ago)
Author:
ryan
Message:

Preserve the $format and $link arguments for passing to the previous|next_post_link filter. Pass $post to the filter.

Props Otto42, helenyhou
fixes #19640 #18764

File:
1 edited

Legend:

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

    r21735 r21802  
    13651365 * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
    13661366 */
    1367 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
     1367function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
    13681368    if ( $previous && is_attachment() )
    13691369        $post = get_post( get_post()->post_parent );
    13701370    else
    1371         $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
    1372 
    1373     if ( !$post )
    1374         return;
    1375 
    1376     $title = $post->post_title;
    1377 
    1378     if ( empty($post->post_title) )
    1379         $title = $previous ? __('Previous Post') : __('Next Post');
    1380 
    1381     $title = apply_filters('the_title', $title, $post->ID);
    1382     $date = mysql2date(get_option('date_format'), $post->post_date);
    1383     $rel = $previous ? 'prev' : 'next';
    1384 
    1385     $string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">';
    1386     $link = str_replace('%title', $title, $link);
    1387     $link = str_replace('%date', $date, $link);
    1388     $link = $string . $link . '</a>';
    1389 
    1390     $format = str_replace('%link', $link, $format);
     1371        $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );
     1372
     1373    if ( ! $post ) {
     1374        $output = '';
     1375    } else {
     1376        $title = $post->post_title;
     1377
     1378        if ( empty( $post->post_title ) )
     1379            $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
     1380
     1381        $title = apply_filters( 'the_title', $title, $post->ID );
     1382        $date = mysql2date( get_option( 'date_format' ), $post->post_date );
     1383        $rel = $previous ? 'prev' : 'next';
     1384
     1385        $string = '<a href="' . get_permalink( $post ) . '" rel="'.$rel.'">';
     1386        $inlink = str_replace( '%title', $title, $link );
     1387        $inlink = str_replace( '%date', $date, $inlink );
     1388        $inlink = $string . $inlink . '</a>';
     1389
     1390        $output = str_replace( '%link', $inlink, $format );
     1391    }
    13911392
    13921393    $adjacent = $previous ? 'previous' : 'next';
    1393     echo apply_filters( "{$adjacent}_post_link", $format, $link );
     1394
     1395    echo apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );
    13941396}
    13951397
Note: See TracChangeset for help on using the changeset viewer.