Make WordPress Core

Changeset 35227


Ignore:
Timestamp:
10/16/2015 09:41:51 PM (8 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy-functions.php

    r35170 r35227  
    752752        $new_term_id = _split_shared_term( $_term->term_id, $_term->term_taxonomy_id );
    753753
    754         // If no split occurred, this is an invalid request.
     754        // If no split occurred, this is an invalid request. Return null (not WP_Error) for back compat.
    755755        if ( $new_term_id === $_term->term_id ) {
    756             return new WP_Error( 'invalid_term', __( 'Empty Term' ) );
     756            return null;
    757757
    758758        // The term has been split. Refetch the term from the proper taxonomy.
  • trunk/tests/phpunit/tests/term/getTerm.php

    r35225 r35227  
    107107        $this->assertInternalType( 'int', $found->term_group );
    108108    }
     109
     110    /**
     111     * @ticket 34332
     112     */
     113     public function test_should_return_null_when_provided_taxonomy_does_not_match_actual_term_taxonomy() {
     114        $term_id = self::$factory->term->create( array( 'taxonomy' => 'post_tag' ) );
     115        $this->assertNull( get_term( $term_id, 'category' ) );
     116    }
    109117}
Note: See TracChangeset for help on using the changeset viewer.