WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 20 hours ago

Last modified 25 minutes ago

#38074 closed enhancement (fixed)

comments_template needs a filter for $top_level_args

Reported by: thomaslhotta Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version: 4.5
Component: Comments Keywords: has-patch needs-dev-note has-unit-tests commit
Focuses: Cc:

Description

Hi,

I am making use of the comments_template_query_args filter to change the way comments are displayed. However the first comments page does not work correctly because $top_level_count is not calculated with the same changes I made in comments_template_query_args.

I can work around this using the WP_Comment_Query filters, but it would be a lot nicer if comments_template_query_args would also effect the calculation of $top_level_count.

Attachments (2)

38074.diff (1.2 KB) - added by Howdy_McGee 8 months ago.
Adds new filter for Top Level Comment Query Args cleverly labelled comments_template_top_level_query_args
38074.2.diff (1.1 KB) - added by garrett-eclipse 3 days ago.
Update the docblock to improve the descriptions and add a description to the array.

Download all attachments as: .zip

Change History (21)

#1 @desrosj
19 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.6.1 to 4.5

Thanks for this, @thomaslhotta. Are you able to create a patch?

@Howdy_McGee
8 months ago

Adds new filter for Top Level Comment Query Args cleverly labelled comments_template_top_level_query_args

#2 @Howdy_McGee
8 months ago

  • Keywords has-patch needs-testing added; needs-patch removed

This ticket was mentioned in Slack in #core by howdy_mcgee. View the logs.


7 months ago

#4 @SergeyBiryukov
7 months ago

  • Milestone changed from Future Release to 5.5
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#5 @SergeyBiryukov
3 months ago

  • Milestone changed from 5.5 to 5.6
  • Type changed from defect (bug) to enhancement

This was accidentally missed in the push for enhancements before 5.5 Beta 1, due to being classified as a bug.

Sorry for that, moving to 5.6.

#6 @hellofromTonya
3 weeks ago

  • Keywords needs-dev-note needs-unit-tests needs-refresh added

Though it's a small patch, it would benefit from a refresh against src.

A new filter is being added. Needs a call-out in the Misc Dev Note.

Suggestion: consider guarding the returned filtered value to validate that it is the data type and value range expected. Adding needs-unit-tests for additional test case scenarios to validate the returned filtered value.

This ticket was mentioned in PR #563 on WordPress/wordpress-develop by dream-encode.


3 weeks ago

  • Keywords needs-refresh removed

Adds a new filter to the comments_template function to allow changes to $top_level_args.

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

This ticket was mentioned in Slack in #core by monikarao. View the logs.


3 weeks ago

#9 follow-up: @Howdy_McGee
3 weeks ago

Thanks @dream-encode for the latest patch!

Via Test Scrub today:
It sounds like the latest patch via Github looks good. We just want to test the new filter against some basic dev and logical test cases. Questions that need answers:

  • Are the reported use-case(s) for this filter valid?
  • Does this filter pass all the necessary variables to make it useful for developers?

#10 in reply to: ↑ 9 @davidbaumwald
3 weeks ago

Replying to Howdy_McGee:

Thanks @dream-encode for the latest patch!

Via Test Scrub today:
It sounds like the latest patch via Github looks good. We just want to test the new filter against some basic dev and logical test cases. Questions that need answers:

  • Are the reported use-case(s) for this filter valid?

I think so. When comments are paged, filtering comments_template_query_args alone leads to a potential mismatch in the offset parameter because there's a pre-query run to set the "top level" comments arguments. This new filter allows for the offset to also take into account any customizations to the main query the developer has in mind.

As mentioned by the reporter, WP_Comment_Query can be filtered as a last resort, and this new filter is a quality of life enhancement. I'd welcome a discussion of an alternate approach.

  • Does this filter pass all the necessary variables to make it useful for developers?

Yes. The $top_level_args parameter is an array of multiple variables, including the post ID of the current post.

To test this in general, comments should be paged. Filter the comments_template_query_args args with something other than the default, filter the same arg in comments_template_top_level_query_args.

This ticket was mentioned in Slack in #core by francina. View the logs.


12 days ago

@garrett-eclipse
3 days ago

Update the docblock to improve the descriptions and add a description to the array.

#12 @garrett-eclipse
3 days ago

Minor refresh in 38074.2.diff to follow the documentation standards and add a description to the array.

This ticket was mentioned in PR #623 on WordPress/wordpress-develop by hellofromtonya.


3 days ago

  • Keywords has-unit-tests added; needs-unit-tests removed

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

  • Applies patch 38074.2.diff
  • Adds unit tests

#14 @prbot
3 days ago

hellofromtonya commented on PR #623:

All tests and checks for this PR pass.

The following test fails for _all new_ PRs:

1) Tests_HTTP_Functions::test_get_response_cookies_with_wp_http_cookie_object
Failed asserting that an array is not empty.
/var/www/tests/phpunit/tests/http/functions.php:140

#15 @hellofromTonya
3 days ago

Added unit tests to patch 38074.2 via PR 623.

Used the strategy @davidbaumwald laid out here

To test this in general, comments should be paged. Filter the comments_template_query_args args with something other than the default, filter the same arg in comments_template_top_level_query_args.

#16 @garrett-eclipse
21 hours ago

  • Keywords commit added; needs-testing removed

Thanks @hellofromTonya for the unit tests, that's awesome nicely done. Things are looking and testing casually for me. Moving forward for commit.

#17 @SergeyBiryukov
20 hours ago

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

In 49256:

Comments: Add a filter for top level comments query arguments in comments_template().

Props hellofromTonya, Howdy_McGee, garrett-eclipse, davidbaumwald, thomaslhotta.
Fixes #38074.

Note: See TracTickets for help on using tickets.