Opened 15 years ago
Closed 14 years ago
#19640 closed defect (bug) (fixed)
adjacent_post_link filter hook missing $post
| Reported by: | tychay | Owned by: | ryan |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | General | Version: | 3.3 |
| Severity: | minor | Keywords: | has-patch |
| Cc: | Focuses: |
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);
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Related: #18674