Make WordPress Core

Opened 2 years ago

Closed 21 months ago

#61094 closed defect (bug) (fixed)

Unsupported `count` argument in `WP_Term_Query` DocBlock

Reported by: Tyrannous Owned by: desrosj
Priority: normal Milestone: 6.7
Component: Taxonomy Version:
Severity: normal Keywords: commit dev-reviewed
Cc: Focuses: docs

Description

The DocBlock of WP_Term_Query::__construct mentions the count argument:

count bool
Whether to return a term count. If true, will take precedence over $fields. Default false.
https://developer.wordpress.org/reference/classes/WP_Term_Query/__construct/

However, this argument is not used in \WP_Term_Query::get_terms, so it should either be removed from the DocBlock or support should be added.

The erroneous DocBlock element has been in core since WordPress 4.6, when WP_Term_Query was introduced in #35381. There, @flixos90 proposed the first iteration of WP_Term_Query in attachment:35381.diff:ticket:35381, which included support for it (lines 347–351). However, when revising the approach in attachment:35381.2.diff:ticket:35381, @boonebgorges kept DocBlock but didn't take over the actual code. This went unnoticed and landed in core.

Note that other WP_*_Query classes indeed support a count argument, so while removing it from the DocBlock would be a quick win, it would probably make more sense to actually add support for it.

Change History (19)

This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.


2 years ago

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


2 years ago
#2

  • Keywords has-patch added

## Ticket
https://core.trac.wordpress.org/ticket/61094

## Description

  • This PR, which involves removing the unsupported count argument from the DocBlock of the WP_Term_Query::__construct method.
  • Currently, the DocBlock mentions the count argument, but it is not utilized in the WP_Term_Query::get_terms method. This leads to potential confusion for developers.

## Changes Made

  • Removed the count argument description from the WP_Term_Query::__construct method's DocBlock.

## Context
The WP_Term_Query class provides methods for querying terms in WordPress. The count argument was initially proposed but later removed from the code, while the DocBlock remained unchanged. This PR aligns the DocBlock with the actual code behaviour, ensuring clarity and consistency in the documentation.

## Testing

  • [ ] Verified that the count argument description is removed from the WP_Term_Query::__construct DocBlock.
  • [ ] Tested the functionality of the WP_Term_Query class to ensure no regressions occurred.
  • [ ] Reviewed and verified the changes locally.

#3 @swissspidy
2 years ago

  • Milestone Awaiting Review6.7

#4 @swissspidy
2 years ago

  • Focuses docs added

#5 follow-up: @Tyrannous
2 years ago

Hi @swissspidy, the attached PR (apparently AI-generated) removes the count DocBlock parameter.
However, as I wrote in the ticket description, wouldn't it make more sense to add support for it to achieve feature parity with other WP_*_Query classes?

Thanks!

@Tyrannous commented on PR #6770:


2 years ago
#6

Hi @snehapatil2001, the PR removes the count DocBlock parameter.
However, as I wrote in the Trac ticket description, wouldn't it make more sense to add support for it to achieve feature parity with other WP_*_Query classes?

Thanks!

#7 in reply to: ↑ 5 @SergeyBiryukov
2 years ago

Hi there, thanks for the ticket!

Replying to Tyrannous:

However, as I wrote in the ticket description, wouldn't it make more sense to add support for it to achieve feature parity with other WP_*_Query classes?

Indeed, I think that would be the preferred solution here.

@jtsternberg commented on PR #6770:


22 months ago
#8

wouldn't it make more sense to add support for it to achieve feature parity with other WP_*_Query classes?

Isn't that what $fields['count'] is for?

https://github.com/WordPress/wordpress-develop/blob/4c2efa2d60e4481186b8218883cc77799205584d/src/wp-includes/class-wp-term-query.php#L315-L324

Also, if we're removing the doc block, we should also remove from query_var_defaults:

https://github.com/WordPress/wordpress-develop/blob/4c2efa2d60e4481186b8218883cc77799205584d/src/wp-includes/class-wp-term-query.php#L209

#9 @peterwilsoncc
21 months ago

I agree adding support for count would be appropriate for the query class. I think a follow up ticket can be created for that as an enhancement.

For the purposes of WordPress 6.7 (which is no longer accepting enhancements) I think removing the documentation is the best fix.

#10 @peterwilsoncc
21 months ago

  • Owner set to peterwilsoncc
  • Resolutionfixed
  • Status newclosed

In 59261:

Taxonomy: Remove count argument from WP_Term_Query docs.

The DocBlock of WP_Term_Query::__construct mentions the count argument, however, this argument is not supported in WP_Term_Query::get_terms().

Props sergeybiryukov, swissspidy, snehapatil02, tyrannous.
Fixes #61094.

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


21 months ago
#12

#13 @johnbillion
21 months ago

  • Resolution fixed
  • Status closedreopened

This is still referenced in two other docs and included as a default value for the args.

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


21 months ago

#15 @peterwilsoncc
21 months ago

  • Resolutionfixed
  • Status reopenedclosed

In 59325:

Taxonomy: Remove count references from WP_Term_Query.

Remove further documentation and a code reference to the unsupported count argument within WP_Term_Query.

Follow up to [59261].

Props johnbillion.
Fixes #61094

#17 @peterwilsoncc
21 months ago

  • Keywords dev-feedback added; has-patch removed
  • Resolution fixed
  • Status closedreopened

Reopening for backport consideration of r59325 to the 6.7 branch upon sign off by a second committer.

#18 @desrosj
21 months ago

  • Keywords commit dev-reviewed added; dev-feedback removed
  • Owner changed from peterwilsoncc to desrosj
  • Status reopenedassigned

#19 @desrosj
21 months ago

  • Resolutionfixed
  • Status assignedclosed

In 59350:

Taxonomy: Remove count references from WP_Term_Query.

Remove further documentation and a code reference to the unsupported count argument within WP_Term_Query.

Follow up to [59261].

Reviewed by peterwilsoncc, desrosj.
Merges [59325] to the 6.7 branch.

Props johnbillion.
Fixes #61094

Note: See TracTickets for help on using tickets.