From 76ffe532d429d17e18b452a53642afa2bc04b30e Mon Sep 17 00:00:00 2001 From: scribu Date: Thu, 14 Oct 2010 07:35:13 +0000 Subject: [PATCH] get_edit_term_link() improvements: * add optional $object_type parameter * make $term_id and $taxonomy parameters mandatory * pass all relevant information to the filter * use in WP_Terms_Table See #9702 git-svn-id: http://svn.automattic.com/wordpress/trunk@15800 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/default-list-tables.php | 2 +- wp-includes/link-template.php | 36 +++++++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index 1b233d455..355a96a98 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -1654,7 +1654,7 @@ class WP_Terms_Table extends WP_List_Table { $pad = str_repeat( '— ', max( 0, $this->level ) ); $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); - $edit_link = "edit-tags.php?action=edit&taxonomy=$taxonomy&post_type=$post_type&tag_ID=$tag->term_id"; + $edit_link = get_edit_term_url( $tag->term_id, $taxonomy, $post_type ); $out = '' . $name . '
'; diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index b50548726..c5f200531 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -649,9 +649,10 @@ function get_tag_feed_link($tag_id, $feed = '') { * @since 2.7.0 * * @param int $tag_id Tag ID + * @param string $taxonomy Taxonomy * @return string */ -function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { +function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { return apply_filters( 'get_edit_tag_link', get_edit_term_url( $tag_id, $taxonomy ) ); } @@ -677,19 +678,29 @@ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { * @since 3.1 * * @param int $term_id Term ID - * @param int $taxonomy Taxonomy + * @param string $taxonomy Taxonomy + * @param string $object_type The object type * @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) ) +function get_edit_term_url( $term_id, $taxonomy, $object_type = '' ) { + $tax = get_taxonomy( $taxonomy ); + if ( !current_user_can( $tax->cap->edit_terms ) ) return; - $term = get_term($term_id, $taxonomy); + $term = get_term( $term_id, $taxonomy ); - $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy .'&tag_ID=' . $term->term_id); + $args = array( + 'action' => 'edit', + 'taxonomy' => $taxonomy, + 'tag_ID' => $term->term_id, + ); - return apply_filters( 'get_edit_term_url', $location ); + if ( $object_type ) + $args['post_type'] = $object_type; + + $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); + + return apply_filters( 'get_edit_term_url', $location, $term_id, $taxonomy, $object_type ); } /** @@ -704,22 +715,21 @@ function get_edit_term_url( $term_id = 0, $taxonomy = 'post_tag' ) { * @return string HTML content. */ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { - - if ( $term == null ) { + if ( is_null( $term ) ) { 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) ) + if ( empty( $link ) ) $link = __('Edit This'); $link = '' . $link . ''; $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; - + if ( $echo ) echo $link; else