mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
get_the_category_by_ID()
should be taxonomy-agnostic.
Prior to 4.9, this function was accidentally taxonomy-agnostic in most cases. The fix in [40979] caused a regression in this function. For backward compatibility, we make it explicit that the query is by ID only. Merges [42367] to the 4.9 branch. See #42771. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@42371 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
85fcc21d30
commit
aac8a92f96
@ -104,7 +104,7 @@ function get_the_category( $id = false ) {
|
||||
*/
|
||||
function get_the_category_by_ID( $cat_ID ) {
|
||||
$cat_ID = (int) $cat_ID;
|
||||
$category = get_term( $cat_ID, 'category' );
|
||||
$category = get_term( $cat_ID );
|
||||
|
||||
if ( is_wp_error( $category ) )
|
||||
return $category;
|
||||
|
53
tests/phpunit/tests/category/getTheCategoryById.php
Normal file
53
tests/phpunit/tests/category/getTheCategoryById.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group taxonomy
|
||||
* @covers ::get_the_category_by_ID
|
||||
*/
|
||||
class Tests_Category_GetTheCategoryById extends WP_UnitTestCase {
|
||||
public function test_success() {
|
||||
$c = self::factory()->category->create( array(
|
||||
'name' => 'Foo',
|
||||
) );
|
||||
|
||||
$found = get_the_category_by_ID( $c );
|
||||
|
||||
$this->assertSame( 'Foo', $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 42771
|
||||
*/
|
||||
public function test_should_return_link_for_term_from_another_taxonomy_on_primed_cache() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'Foo',
|
||||
) );
|
||||
|
||||
$term = get_term( $t );
|
||||
|
||||
$found = get_the_category_by_ID( $t );
|
||||
|
||||
$this->assertSame( 'Foo', $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 42771
|
||||
*/
|
||||
public function test_should_return_link_for_term_from_another_taxonomy_on_empty_cache() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'Foo',
|
||||
) );
|
||||
|
||||
clean_term_cache( $t );
|
||||
|
||||
$found = get_the_category_by_ID( $t );
|
||||
|
||||
$this->assertSame( 'Foo', $found );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user