Make WordPress Core

Opened 8 months ago

Closed 6 months ago

Last modified 6 months ago

#61727 closed enhancement (fixed)

Add `$context` parameter to `get_edit_comment_link()` to get the URL without HTML entities

Reported by: flixos90's profile flixos90 Owned by: flixos90's profile flixos90
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Comments Keywords: good-first-bug has-patch has-unit-tests commit
Focuses: template Cc:

Description

The get_edit_comment_link() function currently always returns its URL with HTML entities included, specifically & (&). This makes sense when including the URL in HTML content, but this may not be the only context where such a link is used.

For exactly the same purpose, the get_edit_post_link() function already has a $context parameter with a default value of "display". Alternatively, "raw" can be provided to not include the HTML entity &, but the regular &.

It would make sense to introduce the same optional $context parameter to get_edit_comment_link(). If "raw" is provided, the function could return the URL to edit the comment without the HTML entity.

Change History (19)

This ticket was mentioned in PR #7071 on WordPress/wordpress-develop by @deepakrohilla.


8 months ago
#1

  • Keywords has-patch added; needs-patch removed

Add $context parameter to get_edit_comment_link() to get the URL without HTML entities

#2 @flixos90
8 months ago

  • Owner set to flixos90
  • Status changed from new to reviewing

@deepakrohilla commented on PR #7071:


8 months ago
#3

@felixarntz Thanks for the suggestion , i will update you today EOD for test case. Thanks again!.

@deepakrohilla commented on PR #7071:


8 months ago
#4

@felixarntz : test case also added please review.

@deepakrohilla commented on PR #7071:


8 months ago
#5

@mukeshpanchal27 : Suggested changes performed , please check Thanks!.

#6 @flixos90
8 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed
  • Milestone changed from Future Release to 6.7

@deepakrohilla commented on PR #7071:


8 months ago
#7

@felixarntz Please check it now

#8 @flixos90
8 months ago

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

In 58875:

Comments: Add optional $context parameter to get_edit_comment_link() to get the URL without HTML entities.

This brings the function in line with the similar get_edit_post_link() parameter. The 'get_edit_comment_link' filter now additionally receives the $comment_id and $context as parameters.

Additionally, as a minor enhancement, the capability check is now more defensive, as it will no longer cause an error if the given comment ID is invalid.

As part of the changeset, comprehensive test coverage for the get_edit_comment_link() including the new behavior is added.

Props deepakrohilla.
Fixes #61727.

#10 @david.binda
6 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Sorry for reopening the ticket, but I've run into an issue where the $comment_id passed as an optional argument to the get_edit_comment_link filter callback is not an int but an object of the WP_Comment class.

This happens in case the object is passed as an argument to the get_edit_comment_link function. The docblock of the get_edit_comment_link function and it's implementation actually allows the WP_Commnet object to be passed in instead of an int.

IMHO, either the documentation of the get_edit_comment_link filter needs to be updated the way it matches such behaviour, or the code needs to be updated the way it ensures the $comment_id param is always an int.

This ticket was mentioned in PR #7322 on WordPress/wordpress-develop by @flixos90.


6 months ago
#11

This is a follow-up fix that addresses the bug in https://core.trac.wordpress.org/ticket/61727#comment:10.

Trac ticket: https://core.trac.wordpress.org/ticket/61727

#12 @flixos90
6 months ago

Thanks @davidbinda, this is a great catch. I implemented a fix in https://github.com/WordPress/wordpress-develop/pull/7322 that ensures the parameter is always the comment ID, which makes more sense for consistent filter behavior.

@peterwilsoncc commented on PR #7322:


6 months ago
#13

@felixarntz This looks good to me but are you able to do a force push of just the test, wait for the actions to complete and then push the fix?

@flixos90 commented on PR #7322:


6 months ago
#14

@peterwilsoncc Done, please see e.g. https://github.com/WordPress/wordpress-develop/actions/runs/10802717139/job/29965357479?pr=7322 for showing the failing test prior to the fix being re-added.

#15 @mukesh27
6 months ago

  • Keywords commit added

Great catch @davidbinda

The PR got enough approval for commit.

#16 @deepakrohilla
6 months ago

Thank you, @davidbinda, for catching that, and thanks to @felixarntz for implementing it further.

#17 @flixos90
6 months ago

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

In 59012:

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.

#19 @flixos90
6 months ago

In 59013:

Comments: Reinstate original since annotation on get_edit_comment_link filter.

This was accidentally removed in [58875].

See #61727.

Note: See TracTickets for help on using tickets.