Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#34332 closed defect (bug) (fixed)

Change in `get_term()` return value with mismatched term ID and taxonomy

Reported by: dlh's profile dlh Owned by: boonebgorges's profile boonebgorges
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Before r34997, calling get_term() with a term ID and a taxonomy that were valid but mismatched would return null. That pairing now returns a WP_Error after get_term() calls _split_shared_term() to no effect.

To demonstrate, this test starts failing after r34997:

function test_get_term_return_value() {
    $term_id = $this->factory->term->create( array( 'taxonomy' => 'post_tag' ) );
    $this->assertNull( get_term( $term_id, 'category' ) );
}

get_term() already returned an error in some situations, so adding one here might not be worth worrying about. In my case, I happened to have a unit test that was not looking for a WP_Error and broke.

Change History (2)

#1 @boonebgorges
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to boonebgorges
  • Status changed from new to assigned

Ah, thanks for the catch, @dlh. It should be fine to return null here. (I'd prefer to standardize on WP_Error, but I care little enough that preserving the previous behavior is probably preferable :) )

#2 @boonebgorges
9 years ago

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

In 35227:

Return null from get_term() on taxonomy mismatch.

[34997] caused get_term() to return an error object in the case when
$taxonomy did not match the taxonomy of the located term. This was an
inadvertant change from the previous behavior, when get_term() would return
null in these cases.

Props dlh.
See #14162. Fixes #34332.

Note: See TracTickets for help on using tickets.