diff --git a/src/wp-includes/category.php b/src/wp-includes/category.php index cbef474490..a89b41065f 100644 --- a/src/wp-includes/category.php +++ b/src/wp-includes/category.php @@ -51,10 +51,16 @@ function get_categories( $args = '' ) { $taxonomy = $args['taxonomy'] = 'link_category'; } - $categories = (array) get_terms( $taxonomy, $args ); + $categories = get_terms( $taxonomy, $args ); - foreach ( array_keys( $categories ) as $k ) - _make_cat_compat( $categories[$k] ); + if ( is_wp_error( $categories ) ) { + $categories = array(); + } else { + $categories = (array) $categories; + foreach ( array_keys( $categories ) as $k ) { + _make_cat_compat( $categories[ $k ] ); + } + } return $categories; } diff --git a/tests/phpunit/tests/category/getCategories.php b/tests/phpunit/tests/category/getCategories.php new file mode 100644 index 0000000000..3f2140dd24 --- /dev/null +++ b/tests/phpunit/tests/category/getCategories.php @@ -0,0 +1,15 @@ + 'foo' ) ); + $this->assertSame( array(), $found ); + } +}