Opened 13 years ago
Closed 12 years ago
#19640 closed defect (bug) (fixed)
adjacent_post_link filter hook missing $post
Reported by: | tychay | Owned by: | 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);
Related: #18674