<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13170] trunk/wp-includes: 2nd pass at Taxonomy Term canonicalisation.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13170">13170</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-02-16 09:08:26 +0000 (Tue, 16 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>2nd pass at Taxonomy Term canonicalisation. Fix get_term_link() to expect null|false||WP_Error failure from get_term() family. See <a href="http://trac.wordpress.org/ticket/12245">#12245</a>, <a href="http://trac.wordpress.org/ticket/8948">#8948</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescanonicalphp">trunk/wp-includes/canonical.php</a></li>
<li><a href="#trunkwpincludestaxonomyphp">trunk/wp-includes/taxonomy.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludescanonicalphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/canonical.php (13169 => 13170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/canonical.php        2010-02-16 04:16:52 UTC (rev 13169)
+++ trunk/wp-includes/canonical.php        2010-02-16 09:08:26 UTC (rev 13170)
</span><span class="lines">@@ -130,27 +130,32 @@
</span><span class="cx">                 } elseif ( is_year() && !empty($_GET['year']) ) {
</span><span class="cx">                         if ( $redirect_url = get_year_link(get_query_var('year')) )
</span><span class="cx">                                 $redirect['query'] = remove_query_arg('year', $redirect['query']);
</span><del>-                } 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']);
</del><span class="cx">                 } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
</span><span class="cx">                         $author = get_userdata(get_query_var('author'));
</span><span class="cx">                         if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )
</span><span class="cx">                                 $redirect['query'] = remove_query_arg('author', $redirect['query']);
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                // 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) ) {
</del><ins>+                // 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']);
+                                }
+
</ins><span class="cx">                                 $tax_url = parse_url($tax_url);
</span><del>-                                $redirect['path'] = $tax_url['path'];
</del><ins>+                                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'];
+                                }
+
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (13169 => 13170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2010-02-16 04:16:52 UTC (rev 13169)
+++ trunk/wp-includes/taxonomy.php        2010-02-16 09:08:26 UTC (rev 13170)
</span><span class="lines">@@ -2290,6 +2290,10 @@
</span><span class="cx">                         $term = &get_term_by('slug', $term, $taxonomy);
</span><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+
+        if ( !is_object($term) )
+                $term = new WP_Error('invalid_term', __('Empty Term'));
+
</ins><span class="cx">         if ( is_wp_error( $term ) )
</span><span class="cx">                 return $term;
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>