Make WordPress Core

Changeset 34246


Ignore:
Timestamp:
09/16/2015 06:49:28 PM (8 years ago)
Author:
boonebgorges
Message:

Failed get_term_by() lookups should always return false.

Previously, we sometimes returned null.

Props charlestonsw, tyxla.
Fixes #33281.

Location:
trunk
Files:
2 edited

Legend:

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

    r34217 r34246  
    804804    } else {
    805805        $term = get_term( (int) $value, $taxonomy, $output, $filter );
    806         if ( is_wp_error( $term ) )
     806        if ( is_wp_error( $term ) || is_null( $term ) ) {
    807807            $term = false;
     808        }
    808809        return $term;
    809810    }
  • trunk/tests/phpunit/tests/term.php

    r32507 r34246  
    5656        $term2 = get_term_by( 'term_taxonomy_id', $term1['term_taxonomy_id'], 'category' );
    5757        $this->assertEquals( get_term( $term1['term_id'], 'category' ), $term2 );
     58    }
     59
     60    /**
     61     * @ticket 33281
     62     */
     63    function test_get_term_by_with_nonexistent_id_should_return_false() {
     64        $term = get_term_by( 'id', 123456, 'category' );
     65        $this->assertFalse( $term );
    5866    }
    5967
Note: See TracChangeset for help on using the changeset viewer.