Make WordPress Core

Opened 5 months ago

Closed 4 months ago

#60563 closed defect (bug) (fixed)

WP_Query::tax_query property could be null

Reported by: manooweb's profile manooweb Owned by: audrasjb's profile audrasjb
Milestone: 6.5 Priority: normal
Severity: trivial Version:
Component: Query Keywords: has-patch commit
Focuses: docs Cc:

Description

By verifying a third party plugin code with PHPStan tool and WordPress stubs, it occurs that in some context WP_Query::tax_query property could be null.

The joined patch propose to enhance the WP_Query::tax_query documentation.

Attachments (1)

doc.patch (444 bytes) - added by manooweb 5 months ago.
WP_Query::tax_query doc enhancement

Download all attachments as: .zip

Change History (9)

@manooweb
5 months ago

WP_Query::tax_query doc enhancement

#1 @sabernhardt
5 months ago

  • Component changed from General to Query
  • Focuses docs added
  • Keywords has-patch added

#2 @audrasjb
5 months ago

  • Milestone changed from Awaiting Review to 6.5
  • Owner set to audrasjb
  • Status changed from new to accepted

Thanks!
Self assigning for final check and commit.

#3 follow-up: @audrasjb
5 months ago

@manooweb quick question: do you have any example of a situation where tax_query could be null?

#4 in reply to: ↑ 3 @manooweb
5 months ago

Replying to audrasjb:

@manooweb quick question: do you have any example of a situation where tax_query could be null?

It isn't so easy to reply.
If I'm not mistaken, I saw tax_query is set only in some conditions by calling WP_Query::parse_tax_query() in WP_Query::parse_query() or WP_Query::get_posts(). So it's possible that this property isn't set and instantiate because WP_Query::parse_tax_query() isn't executed.
https://github.com/WordPress/WordPress/blob/6.4.3/wp-includes/class-wp-query.php#L1372

It's simply a documentation proposition.
When we try to access to the global variable $wp_query (or $wp_the_query) we have no chance to know the tax_query property has been set yet because this property isn't set by the WP_Query instantiation but during the WP_Query::get_posts() execution.

I hope it's clearer.

#5 @swissspidy
5 months ago

  • Keywords commit added

#6 @swissspidy
5 months ago

  • Type changed from enhancement to defect (bug)

#7 @swissspidy
5 months ago

  • Severity changed from normal to trivial

#8 @audrasjb
4 months ago

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

In 57761:

Docs: Update WP_Query::tax_query docblock to reflect that the property can be null.

Props manooweb, swissspidy.
Fixes #60563.

Note: See TracTickets for help on using tickets.