Failed get_term_by()
lookups should always return false
.
Previously, we sometimes returned `null`. Props charlestonsw, tyxla. Fixes #33281. git-svn-id: https://develop.svn.wordpress.org/trunk@34246 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3ca5bbb585
commit
1b016b6dc6
@ -803,8 +803,9 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw
|
||||
$field = 'tt.term_taxonomy_id';
|
||||
} else {
|
||||
$term = get_term( (int) $value, $taxonomy, $output, $filter );
|
||||
if ( is_wp_error( $term ) )
|
||||
if ( is_wp_error( $term ) || is_null( $term ) ) {
|
||||
$term = false;
|
||||
}
|
||||
return $term;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,14 @@ class Tests_Term extends WP_UnitTestCase {
|
||||
$this->assertEquals( get_term( $term1['term_id'], 'category' ), $term2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33281
|
||||
*/
|
||||
function test_get_term_by_with_nonexistent_id_should_return_false() {
|
||||
$term = get_term_by( 'id', 123456, 'category' );
|
||||
$this->assertFalse( $term );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 15919
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user