From cac6d65780f43d633b7a509ff966665ec12011af Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 14 Mar 2016 13:53:28 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@36988 git-svn-id: http://core.svn.wordpress.org/trunk@36955 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category.php | 12 +++++++++--- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-includes/category.php b/wp-includes/category.php index cbef474490..a89b41065f 100644 --- a/wp-includes/category.php +++ b/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/wp-includes/version.php b/wp-includes/version.php index 65ba69e6d4..6e34d63cfe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-beta3-36987'; +$wp_version = '4.5-beta3-36988'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.