Make WordPress Core

Changeset 13170


Ignore:
Timestamp:
02/16/2010 09:08:26 AM (17 years ago)
Author:
dd32
Message:
2nd pass at Taxonomy Term canonicalisation. Fix get_term_link() to expect null|false
WP_Error failure from get_term() family. See #12245, #8948
Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/canonical.php

    r13099 r13170  
    131131                        if ( $redirect_url = get_year_link(get_query_var('year')) )
    132132                                $redirect['query'] = remove_query_arg('year', $redirect['query']);
    133                 } elseif ( is_category() && !empty($_GET['cat']) && preg_match( '|^[0-9]+$|', $_GET['cat'] ) ) {
    134                         if ( $redirect_url = get_category_link(get_query_var('cat')) )
    135                                 $redirect['query'] = remove_query_arg('cat', $redirect['query']);
    136133                } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
    137134                        $author = get_userdata(get_query_var('author'));
    … …  
    140137                }
    141138
    142                 // redirect sub-terms of taxonomies to their correct urls
    143                 if ( is_category() || is_tax() ) {
    144                         if ( is_category() ) {
    145                                 $taxonomy = 'category';
    146                                 $slug = get_query_var('category_name');
    147                         } else {
    148                                 $taxonomy = get_query_var('taxonomy');
    149                                 $slug = get_query_var('term');
    150                         }
    151                         if ( $tax_url = get_term_link($slug, $taxonomy) ) {
     139                // Terms (Tags/categories)
     140                if ( is_category() || is_tag() || is_tax() ) {
     141                        $obj = $wp_query->get_queried_object();
     142                        if ( !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) {
     143
     144                                $redirect['query'] = remove_query_arg( array( 'category_name', 'tag', 'cat', 'tag_id', 'term', 'taxonomy'), $redirect['query']);
     145                                if ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
     146                                        $tax = get_taxonomy( $obj->taxonomy );
     147                                        if ( false !== $tax->query_var)
     148                                                $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
     149                                }
     150
    152151                                $tax_url = parse_url($tax_url);
    153                                 $redirect['path'] = $tax_url['path'];
     152                                if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
     153                                        parse_str($tax_url['query'], $query_vars);
     154                                        $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
     155                                } else { // Taxonomy is accessable via a "pretty-URL"
     156                                        $redirect['path'] = $tax_url['path'];
     157                                }
     158
    154159                        }
    155160                }
  • trunk/wp-includes/taxonomy.php

    r13087 r13170  
    22912291                }
    22922292        }
     2293
     2294        if ( !is_object($term) )
     2295                $term = new WP_Error('invalid_term', __('Empty Term'));
     2296
    22932297        if ( is_wp_error( $term ) )
    22942298                return $term;
Note: See TracChangeset for help on using the changeset viewer.