Ticket #9702: edit_term_link.2.patch

File edit_term_link.2.patch, 3.2 KB (added by joostdevalk, 3 years ago)

Updated patch for edit_term_link, adding get_edit_term_url

  • wp-includes/link-template.php

     
    652652 * @return string 
    653653 */ 
    654654function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { 
    655         global $post_type; 
     655        return apply_filters( 'get_edit_tag_link', get_edit_term_url( $tag_id, $taxonomy ) ); 
     656} 
     657 
     658/** 
     659 * Display or retrieve edit tag link with formatting. 
     660 * 
     661 * @since 2.7.0 
     662 * 
     663 * @param string $link Optional. Anchor text. 
     664 * @param string $before Optional. Display before edit link. 
     665 * @param string $after Optional. Display after edit link. 
     666 * @param int|object $tag Tag object or ID 
     667 * @return string HTML content. 
     668 */ 
     669function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { 
     670        $link = edit_term_link( $link, '', '', false, $tag ); 
     671        echo $before . apply_filters( 'edit_tag_link', $link ) . $after; 
     672} 
     673 
     674/** 
     675 * Retrieve edit tag link. 
     676 * 
     677 * @since 3.1 
     678 * 
     679 * @param int $term_id Term ID 
     680 * @param int $taxonomy Taxonomy 
     681 * @return string 
     682 */ 
     683function get_edit_term_url( $term_id = 0, $taxonomy = 'post_tag' ) { 
    656684        $tax = get_taxonomy($taxonomy); 
    657685        if ( !current_user_can($tax->cap->edit_terms) ) 
    658686                return; 
    659687 
    660         $tag = get_term($tag_id, $taxonomy); 
     688        $term = get_term($term_id, $taxonomy); 
    661689 
    662         $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&' . (!empty($post_type) ? 'post_type=' . $post_type .'&' : '') .'tag_ID=' . $tag->term_id); 
    663         return apply_filters( 'get_edit_tag_link', $location ); 
     690        $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy .'&tag_ID=' . $term->term_id); 
     691         
     692        return apply_filters( 'get_edit_term_url', $location ); 
    664693} 
    665694 
    666695/** 
    667  * Display or retrieve edit tag link with formatting. 
     696 * Display or retrieve edit term link with formatting. 
    668697 * 
    669  * @since 2.7.0 
     698 * @since 3.1 
    670699 * 
    671700 * @param string $link Optional. Anchor text. 
    672701 * @param string $before Optional. Display before edit link. 
    673702 * @param string $after Optional. Display after edit link. 
    674  * @param int|object $tag Tag object or ID 
    675  * @return string|null HTML content, if $echo is set to false. 
     703 * @param object $term Term object 
     704 * @return string HTML content. 
    676705 */ 
    677 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { 
    678         $tax = get_taxonomy('post_tag'); 
     706function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { 
     707         
     708        if ( $term == null ) { 
     709                global $wp_query; 
     710                $term = $wp_query->get_queried_object(); 
     711        } 
     712         
     713        $tax = get_taxonomy( $term->taxonomy ); 
    679714        if ( !current_user_can($tax->cap->edit_terms) ) 
    680715                return; 
    681716 
    682         $tag = get_term($tag, 'post_tag'); 
    683  
    684717        if ( empty($link) ) 
    685718                $link = __('Edit This'); 
    686719 
    687         $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit Tag' ) . '">' . $link . '</a>'; 
    688         echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; 
     720        $link = '<a href="' . get_edit_term_url( $term->term_id, $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>'; 
     721        $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; 
     722         
     723        if ( $echo ) 
     724                echo $link; 
     725        else 
     726                return $link; 
    689727} 
    690728 
    691729/**