From 1b219fcd7a94781c092f1fcf8315a02690798675 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 22 Mar 2010 07:05:50 +0000 Subject: [PATCH] Add some defensive checks to Canonical redirection of %category% to ensure notices are not thrown. Props jfarthing84 for pointing out possibility. See #11907 git-svn-id: https://develop.svn.wordpress.org/trunk@13798 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/canonical.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 428e92ffcb..ae4cac572b 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -167,7 +167,7 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { $category = get_term_by('slug', get_query_var('category_name'), 'category'); $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category'); - if ( ! in_array($category, $post_terms) ) + if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category, $post_terms) ) ) $redirect_url = get_permalink($wp_query->get_queried_object_id()); }