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: http://svn.automattic.com/wordpress/trunk@13798 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-03-22 07:05:50 +00:00
parent 70b7755535
commit 7be1b99ebe
1 changed files with 1 additions and 1 deletions

View File

@ -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());
}