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:
Boone Gorges 2015-09-16 18:49:28 +00:00
parent 3ca5bbb585
commit 1b016b6dc6
2 changed files with 10 additions and 1 deletions

View File

@ -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;
}

View File

@ -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
*/