Make WordPress Core

Opened 2 years ago

Closed 22 months ago

Last modified 22 months ago

#56327 closed defect (bug) (fixed)

Correct returntype for `wp_get_object_terms()`

Reported by: dd32's profile dd32 Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch commit
Focuses: docs Cc:


Currently the wp_get_object_terms() function and the get_object_terms / wp_get_object_terms filters specify that the return value is WP_Term[] or WP_Term[] | WP_Error, but that's not correct.

wp_get_object_terms() ultimately wraps get_terms() and per the $args that are passed through, accepts a field value which is best described by WP_Term_Query::__construct().

As a result, the data-type is better described by the return value of get_terms(): WP_Term[]|int[]|string[]|string|WP_Error. If one assumes the current documentation, you'll likely run into fatal errors when the calling code expected it to be int[] or string[].

Change History (11)

#1 @audrasjb
2 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 6.1

This ticket was mentioned in PR #3056 on WordPress/wordpress-develop by audrasjb.

2 years ago

  • Keywords has-patch added; needs-patch removed

dd32 commented on PR #3056:

2 years ago

Per ticket, this should also touch the filter value for the get_object_terms and wp_get_object_terms filters

#4 @desrosj
22 months ago

  • Keywords changes-requested added

@audrasjb Could you refresh the PR to address the additional items noted by @dd32?

audrasjb commented on PR #3056:

22 months ago

@dd32 PR updated. Does it works for you?

#6 @audrasjb
22 months ago

  • Keywords dev-feedback added; changes-requested removed

I updated the PR accordingly. Waiting for @dd32's feedback before commit.

#7 @mukesh27
22 months ago

  • Keywords changes-requested added

@audrasjb the PR #3056 is closed now. Can you please reopen it as PR looks good to me.

@dd32 can you please review?

#8 @audrasjb
22 months ago

  • Keywords changes-requested removed

Ah yes, thanks, I somehow closed it by mistake :)

Reopened for review.

#9 @mukesh27
22 months ago

  • Keywords commit added; dev-feedback removed

Thanks @audrasjb. PR 3056 looks good to me and approved.

#10 @audrasjb
22 months ago

  • Owner set to audrasjb
  • Resolution set to fixed
  • Status changed from new to closed

In 54441:

Docs: Improve wp_get_object_terms() return type.

Props dd32, audrasjb, desrosj, mukesh27.
Fixes #56327.
See #55646.

Note: See TracTickets for help on using tickets.