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


git-svn-id: http://core.svn.wordpress.org/trunk@21802 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-09-10 21:36:06 +00:00
parent 3205818a04
commit 43a9a11ef9
1 changed files with 19 additions and 17 deletions

View File

@ -1364,33 +1364,35 @@ function next_post_link($format='%link »', $link='%title', $in_same_cat =
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
* @param bool $previous Optional, default is true. Whether to display link to previous or next post. * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
*/ */
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
if ( $previous && is_attachment() ) if ( $previous && is_attachment() )
$post = get_post( get_post()->post_parent ); $post = get_post( get_post()->post_parent );
else else
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );
if ( !$post )
return;
if ( ! $post ) {
$output = '';
} else {
$title = $post->post_title; $title = $post->post_title;
if ( empty($post->post_title) ) if ( empty( $post->post_title ) )
$title = $previous ? __('Previous Post') : __('Next Post'); $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
$title = apply_filters('the_title', $title, $post->ID); $title = apply_filters( 'the_title', $title, $post->ID );
$date = mysql2date(get_option('date_format'), $post->post_date); $date = mysql2date( get_option( 'date_format' ), $post->post_date );
$rel = $previous ? 'prev' : 'next'; $rel = $previous ? 'prev' : 'next';
$string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">'; $string = '<a href="' . get_permalink( $post ) . '" rel="'.$rel.'">';
$link = str_replace('%title', $title, $link); $inlink = str_replace( '%title', $title, $link );
$link = str_replace('%date', $date, $link); $inlink = str_replace( '%date', $date, $inlink );
$link = $string . $link . '</a>'; $inlink = $string . $inlink . '</a>';
$format = str_replace('%link', $link, $format); $output = str_replace( '%link', $inlink, $format );
}
$adjacent = $previous ? 'previous' : 'next'; $adjacent = $previous ? 'previous' : 'next';
echo apply_filters( "{$adjacent}_post_link", $format, $link );
echo apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );
} }
/** /**