WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 8 days ago

#47174 closed defect (bug) (fixed)

Comment reply links are always to first comment form on a page when $withcomments variable is set to true

Reported by: johnh10 Owned by: peterwilsoncc
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.1
Component: Comments Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

This is a follow-up to #33383.

This bug has returned. I'm not sure which version re-introduced this, but the original fix for #33383 (get_permalink) is missing in the current comments-template.php

The WordPress v5.2 code starting at line 1695 of comments-template.php should be:

<?php
                $link = sprintf(
                        "<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
                        esc_url(
                                add_query_arg(
                                        array(
                                                'replytocom'      => $comment->comment_ID,
                                                'unapproved'      => false,
                                                'moderation-hash' => false,
                                        ),
                                        get_permalink($post->ID)
                                )
                        ) . '#' . $args['respond_id'],
                        $data_attribute_string,
                        esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
                        $args['reply_text']
                );

After adding the get_permalink line it works as expected.

Attachments (3)

47174.diff (491 bytes) - added by justinahinon 3 months ago.
47174.2.diff (1.9 KB) - added by donmhico 9 days ago.
Added unit test.
47174.3.diff (1.8 KB) - added by peterwilsoncc 8 days ago.

Download all attachments as: .zip

Change History (10)

#1 @justinahinon
3 months ago

  • Keywords needs-patch needs-testing added
  • Version set to 5.2

Hi @johnh10
Just created a patch for this. I'll track the previous versions changesets to find out where the last one has been removed.

@justinahinon
3 months ago

#2 @earnjam
3 months ago

  • Keywords has-patch added; needs-patch removed
  • Version changed from 5.2 to 5.1

Looks like that get_permalink() arg was removed in [42360], so I think this came back in 5.1.

#3 @peterwilsoncc
3 months ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to peterwilsoncc
  • Status changed from new to accepted

@donmhico
9 days ago

Added unit test.

#4 @donmhico
9 days ago

  • Keywords needs-testing removed

I added unit test in my patch - 47174.2.diff.

Seeing that this issue "resurfaced", a unit test would be beneficially to prevent this from happening again.

@peterwilsoncc
8 days ago

#5 @peterwilsoncc
8 days ago

  • Keywords has-unit-tests added

Thanks @donmhico, you read my mind!

47174.3.diff is almost identical to version 2 with the following changes:

  • some coding standards fixes
  • renamed a couple of variables for clarity to indicate they contain IDs rather than objects

#6 @donmhico
8 days ago

@peterwilsoncc - No problem. I'm reviewing your changes so my future patches would be better. Thank you as well.

#7 @peterwilsoncc
8 days ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 45787:

Comments: Include post permalink in comment reply link.

Include the post's permalink when generating reply links in get_comment_reply_link() to account for comments displayed on index and archive pages.

This reapplies [32786] which was inadvertently reverted in [42360].

Props justinahinon, donmhico.
See #33383.
Fixes #47174.

Note: See TracTickets for help on using tickets.