<!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>[15792] trunk/wp-includes/link-template.php: Introduce edit_term_link()
  and get_term_url().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15792">15792</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-10-13 14:54:21 +0000 (Wed, 13 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce edit_term_link() and get_term_url(). Props yoast. Fixes <a href="http://trac.wordpress.org/ticket/9702">#9702</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludeslinktemplatephp">trunk/wp-includes/link-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludeslinktemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/link-template.php (15791 => 15792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/link-template.php        2010-10-13 13:45:53 UTC (rev 15791)
+++ trunk/wp-includes/link-template.php        2010-10-13 14:54:21 UTC (rev 15792)
</span><span class="lines">@@ -652,40 +652,78 @@
</span><span class="cx">  * @return string
</span><span class="cx">  */
</span><span class="cx"> function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
</span><del>-        global $post_type;
</del><ins>+        return apply_filters( 'get_edit_tag_link', get_edit_term_url( $tag_id, $taxonomy ) );
+}
+
+/**
+ * Display or retrieve edit tag link with formatting.
+ *
+ * @since 2.7.0
+ *
+ * @param string $link Optional. Anchor text.
+ * @param string $before Optional. Display before edit link.
+ * @param string $after Optional. Display after edit link.
+ * @param int|object $tag Tag object or ID
+ * @return string HTML content.
+ */
+function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
+        $link = edit_term_link( $link, '', '', false, $tag );
+        echo $before . apply_filters( 'edit_tag_link', $link ) . $after;
+}
+
+/**
+ * Retrieve edit term url.
+ *
+ * @since 3.1
+ *
+ * @param int $term_id Term ID
+ * @param int $taxonomy Taxonomy
+ * @return string
+ */
+function get_edit_term_url( $term_id = 0, $taxonomy = 'post_tag' ) {
</ins><span class="cx">         $tax = get_taxonomy($taxonomy);
</span><span class="cx">         if ( !current_user_can($tax-&gt;cap-&gt;edit_terms) )
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        $tag = get_term($tag_id, $taxonomy);
</del><ins>+        $term = get_term($term_id, $taxonomy);
</ins><span class="cx"> 
</span><del>-        $location = admin_url('edit-tags.php?action=edit&amp;amp;taxonomy=' . $taxonomy . '&amp;amp;' . (!empty($post_type) ? 'post_type=' . $post_type .'&amp;amp;' : '') .'tag_ID=' . $tag-&gt;term_id);
-        return apply_filters( 'get_edit_tag_link', $location );
</del><ins>+        $location = admin_url('edit-tags.php?action=edit&amp;amp;taxonomy=' . $taxonomy .'&amp;amp;tag_ID=' . $term-&gt;term_id);
+
+        return apply_filters( 'get_edit_term_url', $location );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Display or retrieve edit tag link with formatting.
</del><ins>+ * Display or retrieve edit term link with formatting.
</ins><span class="cx">  *
</span><del>- * @since 2.7.0
</del><ins>+ * @since 3.1
</ins><span class="cx">  *
</span><span class="cx">  * @param string $link Optional. Anchor text.
</span><span class="cx">  * @param string $before Optional. Display before edit link.
</span><span class="cx">  * @param string $after Optional. Display after edit link.
</span><del>- * @param int|object $tag Tag object or ID
- * @return string|null HTML content, if $echo is set to false.
</del><ins>+ * @param object $term Term object
+ * @return string HTML content.
</ins><span class="cx">  */
</span><del>-function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
-        $tax = get_taxonomy('post_tag');
</del><ins>+function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
+        
+        if ( $term == null ) {
+                global $wp_query;
+                $term = $wp_query-&gt;get_queried_object();
+        }
+        
+        $tax = get_taxonomy( $term-&gt;taxonomy );
</ins><span class="cx">         if ( !current_user_can($tax-&gt;cap-&gt;edit_terms) )
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        $tag = get_term($tag, 'post_tag');
-
</del><span class="cx">         if ( empty($link) )
</span><span class="cx">                 $link = __('Edit This');
</span><span class="cx"> 
</span><del>-        $link = '&lt;a href=&quot;' . get_edit_tag_link( $tag-&gt;term_id ) . '&quot; title=&quot;' . __( 'Edit Tag' ) . '&quot;&gt;' . $link . '&lt;/a&gt;';
-        echo $before . apply_filters( 'edit_tag_link', $link, $tag-&gt;term_id ) . $after;
</del><ins>+        $link = '&lt;a href=&quot;' . get_edit_term_url( $term-&gt;term_id, $term-&gt;taxonomy ) . '&quot; title=&quot;' . $link . '&quot;&gt;' . $link . '&lt;/a&gt;';
+        $link = $before . apply_filters( 'edit_term_link', $link, $term-&gt;term_id ) . $after;
+        
+        if ( $echo )
+                echo $link;
+        else
+                return $link;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>