#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 has-unit-tests commit has-dev-note |
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)
Change History (22)
#1
@
5 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
- Version changed from 4.6.1 to 4.5
@
5 years ago
Adds new filter for Top Level Comment Query Args cleverly labelled comments_template_top_level_query_args
This ticket was mentioned in Slack in #core by howdy_mcgee. View the logs.
4 years ago
#4
@
4 years ago
- Milestone changed from Future Release to 5.5
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
#5
@
4 years 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
@
4 years 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.
4 years ago
#7
- 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.
4 years ago
#9
follow-up:
↓ 10
@
4 years 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
@
4 years 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.
4 years ago
#12
@
4 years 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.
4 years ago
#13
- 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
hellofromtonya commented on PR #623:
4 years ago
#14
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
@
4 years 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
@
4 years 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.
dream-encode commented on PR #563:
4 years ago
#18
dream-encode commented on PR #623:
4 years ago
#19
Merged into WP Core in https://core.trac.wordpress.org/changeset/49256
Thanks for this, @thomaslhotta. Are you able to create a patch?