Make WordPress Core

Changeset 36988


Ignore:
Timestamp:
03/14/2016 01:52:14 PM (8 years ago)
Author:
boonebgorges
Message:

Improve error handling in get_categories().

When passed an invalid 'taxonomy', get_terms() will return a WP_Error
object. This object should not be blindly cast to an array. Instead, an empty
array should be returned, to indicate that no matching terms have been found.

Props virgodesign, sebastian.pisula.
Fixes #36227.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r36476 r36988  
    5252    }
    5353
    54     $categories = (array) get_terms( $taxonomy, $args );
    55 
    56     foreach ( array_keys( $categories ) as $k )
    57         _make_cat_compat( $categories[$k] );
     54    $categories = get_terms( $taxonomy, $args );
     55
     56    if ( is_wp_error( $categories ) ) {
     57        $categories = array();
     58    } else {
     59        $categories = (array) $categories;
     60        foreach ( array_keys( $categories ) as $k ) {
     61            _make_cat_compat( $categories[ $k ] );
     62        }
     63    }
    5864
    5965    return $categories;
Note: See TracChangeset for help on using the changeset viewer.