WordPress.org

Make WordPress Core

#50344 closed defect (bug) (fixed)

Update @return docs for get_tags() to reflect that WP_Error is a possible return value

Reported by: coffee2code Owned by: SergeyBiryukov
Milestone: 5.5 Priority: low
Severity: minor Version:
Component: Taxonomy Keywords: has-patch
Focuses: docs Cc:

Description

get_tags(), by virtue of its call to get_terms(), has the potential to return a WP_Error object (if a specified taxonomy does not exist).

Unlike the similar get_categories(), get_tags() does not check for an error and return an empty array if there is one, so a WP_Error object can be returned by get_tags().

Patch attached.

Quick demonstration of return value:

$ wp eval "var_dump( get_tags( [ 'taxonomy' => 'xyz' ] ) );"
object(WP_Error)#1621 (2) {
  ["errors"]=>
  array(1) {
    ["invalid_taxonomy"]=>
    array(1) {
      [0]=>
      string(17) "Invalid taxonomy."
    }
  }
  ["error_data"]=>
  array(0) {
  }
}

Attachments (1)

50344.diff (724 bytes) - added by coffee2code 18 months ago.
Patch mentioned in ticket.

Download all attachments as: .zip

Change History (3)

@coffee2code
18 months ago

Patch mentioned in ticket.

#1 @SergeyBiryukov
18 months ago

  • Milestone changed from Awaiting Review to 5.5
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#2 @SergeyBiryukov
18 months ago

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

In 47930:

Docs: Document that get_tags() returns a WP_Error object if any of the specified taxonomies do not exist.

Props coffee2code.
Fixes #50344.

Note: See TracTickets for help on using tickets.