From c9190d87d5349f45f92535c690bffd6cc0578c5f Mon Sep 17 00:00:00 2001 From: scribu Date: Wed, 13 Oct 2010 14:54:21 +0000 Subject: [PATCH] Introduce edit_term_link() and get_term_url(). Props yoast. Fixes #9702 git-svn-id: http://svn.automattic.com/wordpress/trunk@15792 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 66 +++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 768fe6312..b50548726 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -652,15 +652,7 @@ function get_tag_feed_link($tag_id, $feed = '') { * @return string */ function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { - global $post_type; - $tax = get_taxonomy($taxonomy); - if ( !current_user_can($tax->cap->edit_terms) ) - return; - - $tag = get_term($tag_id, $taxonomy); - - $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&' . (!empty($post_type) ? 'post_type=' . $post_type .'&' : '') .'tag_ID=' . $tag->term_id); - return apply_filters( 'get_edit_tag_link', $location ); + return apply_filters( 'get_edit_tag_link', get_edit_term_url( $tag_id, $taxonomy ) ); } /** @@ -672,20 +664,66 @@ function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { * @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|null HTML content, if $echo is set to false. + * @return string HTML content. */ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { - $tax = get_taxonomy('post_tag'); + $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' ) { + $tax = get_taxonomy($taxonomy); if ( !current_user_can($tax->cap->edit_terms) ) return; - $tag = get_term($tag, 'post_tag'); + $term = get_term($term_id, $taxonomy); + + $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy .'&tag_ID=' . $term->term_id); + + return apply_filters( 'get_edit_term_url', $location ); +} + +/** + * Display or retrieve edit term link with formatting. + * + * @since 3.1 + * + * @param string $link Optional. Anchor text. + * @param string $before Optional. Display before edit link. + * @param string $after Optional. Display after edit link. + * @param object $term Term object + * @return string HTML content. + */ +function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { + + if ( $term == null ) { + global $wp_query; + $term = $wp_query->get_queried_object(); + } + + $tax = get_taxonomy( $term->taxonomy ); + if ( !current_user_can($tax->cap->edit_terms) ) + return; if ( empty($link) ) $link = __('Edit This'); - $link = '' . $link . ''; - echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; + $link = '' . $link . ''; + $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; + + if ( $echo ) + echo $link; + else + return $link; } /**