Make WordPress Core

Opened 13 years ago

Closed 12 years ago

#19640 closed defect (bug) (fixed)

adjacent_post_link filter hook missing $post

Reported by: tychay's profile tychay Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: minor Version: 3.3
Component: General Keywords: has-patch
Focuses: Cc:

Description

wp-includes/link-template.php, line 1369

is:
apply_filters( "{$adjacent}_post_link", $format, $link );

should be:
apply_filters( "{$adjacent}_post_link", $format, $link, $post );

Reason:
Users may want to do replacement in post link that requires information about the post. For instance, inserting the author into the link. Example, if the post link format contains "%author" the following code will inject the author name of the next/previous post into it.

function advent_author_format_link($format, $link, $post) {

$author = get_userdata($post->post_author);
$format = str_replace('%author', $author->display_name, $format);
return $format;
return array(

'format' => $format,
'post' => $post,

);

}
add_action('previous_post_link', 'advent_author_format_link', 10, 3);
add_action('next_post_link', 'advent_author_format_link', 10, 3);

Attachments (1)

19640.diff (473 bytes) - added by helenyhou 12 years ago.

Download all attachments as: .zip

Change History (5)

@helenyhou
12 years ago

#2 @helenyhou
12 years ago

  • Keywords has-patch added

#3 @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.5

Let's be sure to handle this with #18674.

#4 @ryan
12 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21802]:

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

Note: See TracTickets for help on using tickets.