Make WordPress Core

Changeset 45787


Ignore:
Timestamp:
08/13/2019 05:08:14 AM (5 years ago)
Author:
peterwilsoncc
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r45742 r45787  
    16981698                        'unapproved'      => false,
    16991699                        'moderation-hash' => false,
    1700                     )
     1700                    ),
     1701                    get_permalink( $post->ID )
    17011702                )
    17021703            ) . '#' . $args['respond_id'],
  • trunk/tests/phpunit/tests/comment/getCommentReplyLink.php

    r42343 r45787  
    2727        $this->assertNull( get_comment_reply_link( $args ) );
    2828    }
     29
     30    /**
     31     * Ensure comment reply links include post permalink.
     32     *
     33     * @ticket 47174
     34     */
     35    public function test_get_comment_reply_link_should_include_post_permalink() {
     36        // Create a sample post.
     37        $post_id = self::factory()->post->create();
     38
     39        // Insert comment.
     40        $comment_id = self::factory()->comment->create(
     41            array(
     42                'comment_post_ID' => $post_id,
     43                'user_id'         => 1,
     44            )
     45        );
     46
     47        // `depth` and `max_depth` required for reply links to display.
     48        $comment_reply_link = get_comment_reply_link(
     49            array(
     50                'depth'     => 1,
     51                'max_depth' => 5,
     52            ),
     53            $comment_id,
     54            $post_id
     55        );
     56
     57        $expected_url = esc_url(
     58            add_query_arg(
     59                array(
     60                    'p'          => $post_id,
     61                    'replytocom' => $comment_id,
     62                ),
     63                home_url( '/#respond' )
     64            )
     65        );
     66
     67        $this->assertContains( $expected_url, $comment_reply_link );
     68    }
    2969}
Note: See TracChangeset for help on using the changeset viewer.