mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
2nd pass at Taxonomy Term canonicalisation. Fix get_term_link() to expect null|false||WP_Error failure from get_term() family. See #12245, #8948
git-svn-id: http://svn.automattic.com/wordpress/trunk@13170 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9cabc34e63
commit
9d2b6b6047
@ -130,27 +130,32 @@ function redirect_canonical($requested_url=null, $do_redirect=true) {
|
||||
} elseif ( is_year() && !empty($_GET['year']) ) {
|
||||
if ( $redirect_url = get_year_link(get_query_var('year')) )
|
||||
$redirect['query'] = remove_query_arg('year', $redirect['query']);
|
||||
} elseif ( is_category() && !empty($_GET['cat']) && preg_match( '|^[0-9]+$|', $_GET['cat'] ) ) {
|
||||
if ( $redirect_url = get_category_link(get_query_var('cat')) )
|
||||
$redirect['query'] = remove_query_arg('cat', $redirect['query']);
|
||||
} elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
|
||||
$author = get_userdata(get_query_var('author'));
|
||||
if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )
|
||||
$redirect['query'] = remove_query_arg('author', $redirect['query']);
|
||||
}
|
||||
|
||||
// redirect sub-terms of taxonomies to their correct urls
|
||||
if ( is_category() || is_tax() ) {
|
||||
if ( is_category() ) {
|
||||
$taxonomy = 'category';
|
||||
$slug = get_query_var('category_name');
|
||||
} else {
|
||||
$taxonomy = get_query_var('taxonomy');
|
||||
$slug = get_query_var('term');
|
||||
}
|
||||
if ( $tax_url = get_term_link($slug, $taxonomy) ) {
|
||||
// Terms (Tags/categories)
|
||||
if ( is_category() || is_tag() || is_tax() ) {
|
||||
$obj = $wp_query->get_queried_object();
|
||||
if ( !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) {
|
||||
|
||||
$redirect['query'] = remove_query_arg( array( 'category_name', 'tag', 'cat', 'tag_id', 'term', 'taxonomy'), $redirect['query']);
|
||||
if ( 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']);
|
||||
}
|
||||
|
||||
$tax_url = parse_url($tax_url);
|
||||
$redirect['path'] = $tax_url['path'];
|
||||
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'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2290,6 +2290,10 @@ function get_term_link( $term, $taxonomy ) {
|
||||
$term = &get_term_by('slug', $term, $taxonomy);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !is_object($term) )
|
||||
$term = new WP_Error('invalid_term', __('Empty Term'));
|
||||
|
||||
if ( is_wp_error( $term ) )
|
||||
return $term;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user