Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#29454 closed defect (bug) (fixed)

comments_link filter can not be run on comments_popup_link if post has no comments.

Reported by: joedolson's profile joedolson Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 2.5
Component: Comments Keywords:
Focuses: template Cc:

Description

The filter 'comments_link' is run in the function comments_link(), called by comments_popup_link(). However, if a post has no comments, it doesn't call comments_link(); it calls get_permalink() and appends hashtag fragment (basically, recreating what comments_link() does.)

This means that you can't filter the comments link separately from the permalink if a post has no comments.

Additionally, comments_link() is a deprecated function, so core shouldn't be using it.

Patch uses get_comments_link regardless of number of comments & removes comments_link from function.

Attachments (2)

29454.patch (632 bytes) - added by joedolson 10 years ago.
Use get_comments_link() instead of get_permalink/comments_link
29454.2.patch (937 bytes) - added by joedolson 10 years ago.
Add respond_link filter to comments_link()

Download all attachments as: .zip

Change History (9)

@joedolson
10 years ago

Use get_comments_link() instead of get_permalink/comments_link

#1 @SergeyBiryukov
10 years ago

Additionally, comments_link() is a deprecated function, so core shouldn't be using it.

comments_link() has two deprecated arguments, but the function itself is not deprecated.

#2 @joedolson
10 years ago

Ah - moving too quickly; misread that. Regardless, the rest of the statement stands.

#3 @helen
10 years ago

  • Version changed from trunk to 2.5

Been this way since [6372].

#4 @SergeyBiryukov
10 years ago

comments_link() has an additional benefit of esc_url() after the filter, we should keep using it here.

Note that get_permalink() . '#respond' is a direct link to the comment form, while comments_link() is a link to the comments block. There is no difference in default themes with no comments, but there might be a difference in other themes.

Perhaps we could add a new filter, get_respond_link.

#5 @joedolson
10 years ago

I think that a new filter would definitely work, too - I'll add a patch for that, instead. Practically speaking, the important thing is to be able to filter the comment link whether the post has comments or not; using get_respond_link as a filter would fulfill that.

For consistency, I think that the filter should probably be respond_link, since it's run in a printing function.

@joedolson
10 years ago

Add respond_link filter to comments_link()

#6 @wonderboymusic
9 years ago

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

In 34216:

Apply the new 'respond_link' filter in comments_popup_link() if $number is 0 before outputting the URL.

Props joedolson.
Fixes #29454.

#7 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to 4.4
Note: See TracTickets for help on using tickets.