Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#35808 closed defect (bug) (fixed)

get_term() possible PHP fatal error

Reported by: tmuikku's profile tmuikku Owned by: boonebgorges's profile boonebgorges
Milestone: 4.5 Priority: normal
Severity: normal Version: 4.4
Component: General Keywords:
Focuses: ui, template, multisite, performance Cc:


I noticed occasional fatal error from get_term() function when a get_term filter or get_{$taxonomy} filter returns something else than WP_Term object.

In my case it is WPML in a rare multisite scenario causing this, but nevertheless it would be good to do another check if $_term is indeed a WP_Term before the filter method call in wp-includes/taxonomy.php line ~800.

    $_term = apply_filters( 'get_term', $_term, $taxonomy );
    $_term = apply_filters( "get_$taxonomy", $_term, $taxonomy );

    // Maybe check here if the filters returned error
    if ( is_wp_error( $_term ) ) {
        return $_term;
    } elseif ( ! $_term ) {
        return null;

    // Sanitize term, according to the specified filter.
    $_term->filter( $filter );

Change History (2)

#1 @boonebgorges
8 years ago

  • Milestone changed from Awaiting Review to 4.5
  • Owner set to boonebgorges
  • Status changed from new to assigned
  • Type changed from enhancement to defect (bug)
  • Version changed from trunk to 4.4

Hi @tmuikku - Thanks for the report, and welcome to WordPress Trac! This looks like a legitimate issue.

#2 @boonebgorges
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 36516:

Bail from get_term() if a filter returns an object that is not a WP_Term.

This prevents fatal errors in certain cases.

Props tmuikku.
Fixes #35808.

Note: See TracTickets for help on using tickets.