+ if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )
+ $redirect['query'] = remove_query_arg('author', $redirect['query']);
+ } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories)
+
+ $term_count = 0;
+ foreach ( array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
+ 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key )
+ $term_count += count($wp_query->query_vars[$key]);
+
+ $obj = $wp_query->get_queried_object();
+
+ if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) )
+ && !is_wp_error($tax_url) && $redirect['query'] ) {
+ if ( is_category() ) {
+ $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
+ } elseif ( is_tag() ) {
+ $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
+ } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
+ $tax = get_taxonomy( $obj->taxonomy );
+ if ( false !== $tax->query_var)
+ $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
+ else
+ $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
+ }
+
+ $tax_url = parse_url($tax_url);
+ if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
+ parse_str($tax_url['query'], $query_vars);
+ $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
+ } else { // Taxonomy is accessable via a "pretty-URL"
+ $redirect['path'] = $tax_url['path'];
+ }
+
+ }
+ } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
+ $category = get_category_by_path(get_query_var('category_name'));
+ $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
+ if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) )
+ $redirect_url = get_permalink($wp_query->get_queried_object_id());