Skip to content

Commit b18e0e1

Browse files
committed
Comments: Ensure $comment_id parameter on get_edit_comment_link filter is always a comment ID.
Follow up to [58875]. Props david.binda, peterwilsoncc, mukesh27, davidbaumwald. Fixes #61727. git-svn-id: https://develop.svn.wordpress.org/trunk@59012 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 38243be commit b18e0e1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/wp-includes/link-template.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,14 +1618,17 @@ function get_edit_comment_link( $comment_id = 0, $context = 'display' ) {
16181618

16191619
$location = admin_url( $action ) . $comment->comment_ID;
16201620

1621+
// Ensure the $comment_id variable passed to the filter is always an ID.
1622+
$comment_id = (int) $comment->comment_ID;
1623+
16211624
/**
16221625
* Filters the comment edit link.
16231626
*
16241627
* @since 6.7.0 The $comment_id and $context parameters are now being passed to the filter.
16251628
*
1626-
* @param string $location The edit link.
1627-
* @param int $comment_id Optional. Unique ID of the comment to generate an edit link.
1628-
* @param int $context Optional. Context to include HTML entities in link. Default 'display'.
1629+
* @param string $location The edit link.
1630+
* @param int $comment_id Unique ID of the comment to generate an edit link.
1631+
* @param string $context Context to include HTML entities in link. Default 'display'.
16291632
*/
16301633
return apply_filters( 'get_edit_comment_link', $location, $comment_id, $context );
16311634
}

tests/phpunit/tests/link/getEditCommentLink.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,29 @@ function ( $location, $comment_id, $context ) {
127127
$this->assertSame( $expected_url_display, $actual_url_display );
128128
$this->assertSame( $expected_url, $actual_url );
129129
}
130+
131+
/**
132+
* Tests that the 'get_edit_comment_link' filter receives the comment ID, even when a comment object is passed.
133+
*
134+
* @ticket 61727
135+
*/
136+
public function test_get_edit_comment_link_filter_uses_id() {
137+
// Add a filter just to catch the $comment_id filter parameter value.
138+
$comment_id_filter_param = null;
139+
add_filter(
140+
'get_edit_comment_link',
141+
function ( $location, $comment_id ) use ( &$comment_id_filter_param ) {
142+
$comment_id_filter_param = $comment_id;
143+
return $location;
144+
},
145+
10,
146+
2
147+
);
148+
149+
// Pass a comment object to get_edit_comment_link().
150+
get_edit_comment_link( get_comment( self::$comment_id ) );
151+
152+
// The filter should still always receive the comment ID, not the object.
153+
$this->assertSame( self::$comment_id, $comment_id_filter_param );
154+
}
130155
}

0 commit comments

Comments
 (0)