Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54222 closed defect (bug) (fixed)

Document that the `get_terms` filter can have null for `$taxonomies`

Reported by: dd32's profile dd32 Owned by: davidbaumwald's profile davidbaumwald
Milestone: 5.9 Priority: normal
Severity: minor Version:
Component: Taxonomy Keywords: has-patch
Focuses: docs Cc:

Description

The get_terms filter currently documents that the filter passes an array as both the first and second parameters, which is normally true, except that the second can be null when not specified.

The simplest way to trigger this scenario is to query for get_terms( [ 'term_taxonomy_id' => ?? ] ); which has no taxonomies to pass.

This can cause PHP Warnings and PHP Fatal errors in code that doesn't expect it.

See some real world examples:

Change History (8)

This ticket was mentioned in PR #1732 on WordPress/wordpress-develop by dd32.


3 years ago
#1

  • Keywords has-patch added

#2 follow-up: @audrasjb
3 years ago

  • Milestone changed from Awaiting Review to 5.9

Moving this for 5.9 consideration.
I'm wondering whether this should also be documented in other functions (like wp_terms_checklist and many others) or not.
Otherwise the PR looks good to me.

#3 in reply to: ↑ 2 @dd32
3 years ago

Replying to audrasjb:

I'm wondering whether this should also be documented in other functions (like wp_terms_checklist and many others) or not.

I'm not sure where that comes into play having taken a quick look at those, this is just that one of the additional context parameters on the get_terms filter is documented wrong, doesn't affect the return value (which is already Documented as being literally almost anything WP_Term[]|int[]|string[]|string|WP_Error :) ).

#4 @audrasjb
3 years ago

Ok, makes sense to me, thanks for checking :)

#5 @mukesh27
3 years ago

PR looks good to me.

Ready to commit

#6 @davidbaumwald
3 years ago

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

#7 @davidbaumwald
3 years ago

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

In 52131:

Taxonomy: Document that the get_terms filter can have null for $taxonomies.

The get_terms filter currently documents that the filter passes an array as both the first and second parameters, which is normally true, except that the second can be null when not specified. This change updates the filter's docblock to indicate that the second parameter can also be of a null type.

Props dd32, audrasjb, mukesh27.
Fixes #54222.

dream-encode commented on PR #1732:


3 years ago
#8

Committed to core in changeset https://core.trac.wordpress.org/changeset/52131.

Note: See TracTickets for help on using tickets.