Make WordPress Core

Ticket #12659: 12659.diff

File 12659.diff, 4.6 KB (added by dd32, 15 years ago)

Initial scratch-run at it.

  • wp-includes/canonical.php

     
    155155
    156156                        $obj = $wp_query->get_queried_object();
    157157
    158                         if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) )
    159                                         && !is_wp_error($tax_url) && $redirect['query'] ) {
    160                                 if ( is_category() ) {
    161                                         $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    162                                 } elseif ( is_tag() ) {
    163                                         $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    164                                 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
    165                                         $tax = get_taxonomy( $obj->taxonomy );
    166                                         if ( false !== $tax->query_var)
    167                                                 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
    168                                         else
    169                                                 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
     158                        if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) {
     159                                if ( !empty($redirect['query']) ) {
     160                                        if ( is_category() ) {
     161                                                $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
     162                                        } elseif ( is_tag() ) {
     163                                                $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
     164                                        } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
     165                                                $tax = get_taxonomy( $obj->taxonomy );
     166                                                if ( false !== $tax->query_var)
     167                                                        $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
     168                                                else
     169                                                        $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
     170                                        }
    170171                                }
    171 
    172172                                $tax_url = parse_url($tax_url);
    173173                                if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
    174174                                        parse_str($tax_url['query'], $query_vars);
     
    176176                                } else { // Taxonomy is accessable via a "pretty-URL"
    177177                                        $redirect['path'] = $tax_url['path'];
    178178                                }
    179 
    180179                        }
    181180                } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
    182181                        $category = get_term_by('slug', get_query_var('category_name'), 'category');
  • wp-includes/taxonomy.php

     
    270270                $wp_taxonomies = array();
    271271
    272272        $defaults = array(      'hierarchical' => false,
     273                                                'hierarchical_uri' => false,
    273274                                                'update_count_callback' => '',
    274275                                                'rewrite' => true,
    275276                                                'query_var' => $taxonomy,
     
    295296                        'slug' => sanitize_title_with_dashes($taxonomy),
    296297                        'with_front' => true,
    297298                ));
    298                 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
     299                if ( $args['hierarchical'] && $args['hierarchical_uri'] )
     300                        $wp_rewrite->add_rewrite_tag("%$taxonomy%", '.*?/?([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
     301                else
     302                        $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
    299303                $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);
    300304        }
    301305
     
    25942598        $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    25952599
    25962600        $slug = $term->slug;
     2601        $t = get_taxonomy($taxonomy);
    25972602
    25982603        if ( empty($termlink) ) {
    2599                 $t = get_taxonomy($taxonomy);
    26002604                if ( $t->query_var )
    26012605                        $termlink = "?$t->query_var=$slug";
    26022606                else
    26032607                        $termlink = "?taxonomy=$taxonomy&term=$slug";
    26042608                $termlink = home_url($termlink);
    26052609        } else {
    2606                 $termlink = str_replace("%$taxonomy%", $slug, $termlink);
     2610                if ( $t->hierarchical_uri ) {
     2611                        $hierarchical_slugs = array();
     2612                        $ancestors = get_ancestors($term->term_id, $taxonomy);
     2613                        foreach ( (array)$ancestors as $ancestor ) {
     2614                                $ancestor_term = get_term($ancestor, $taxonomy);
     2615                                $hierarchical_slugs[] = $ancestor_term->slug;
     2616                        }
     2617                        $hierarchical_slugs = array_reverse($hierarchical_slugs);
     2618                        $hierarchical_slugs[] = $slug;
     2619                        $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
     2620                } else {
     2621                        $termlink = str_replace("%$taxonomy%", $slug, $termlink);
     2622                }
    26072623                $termlink = home_url( user_trailingslashit($termlink, 'category') );
    26082624        }
    26092625        return apply_filters('term_link', $termlink, $term, $taxonomy);