Make WordPress Core

Changeset 15792


Ignore:
Timestamp:
10/13/2010 02:54:21 PM (14 years ago)
Author:
scribu
Message:

Introduce edit_term_link() and get_term_url(). Props yoast. Fixes #9702

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r15746 r15792  
    653653 */
    654654function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
    655     global $post_type;
    656     $tax = get_taxonomy($taxonomy);
    657     if ( !current_user_can($tax->cap->edit_terms) )
    658         return;
    659 
    660     $tag = get_term($tag_id, $taxonomy);
    661 
    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 );
     655    return apply_filters( 'get_edit_tag_link', get_edit_term_url( $tag_id, $taxonomy ) );
    664656}
    665657
     
    673665 * @param string $after Optional. Display after edit link.
    674666 * @param int|object $tag Tag object or ID
    675  * @return string|null HTML content, if $echo is set to false.
     667 * @return string HTML content.
    676668 */
    677669function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
    678     $tax = get_taxonomy('post_tag');
     670    $link = edit_term_link( $link, '', '', false, $tag );
     671    echo $before . apply_filters( 'edit_tag_link', $link ) . $after;
     672}
     673
     674/**
     675 * Retrieve edit term url.
     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' ) {
     684    $tax = get_taxonomy($taxonomy);
    679685    if ( !current_user_can($tax->cap->edit_terms) )
    680686        return;
    681687
    682     $tag = get_term($tag, 'post_tag');
     688    $term = get_term($term_id, $taxonomy);
     689
     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 );
     693}
     694
     695/**
     696 * Display or retrieve edit term link with formatting.
     697 *
     698 * @since 3.1
     699 *
     700 * @param string $link Optional. Anchor text.
     701 * @param string $before Optional. Display before edit link.
     702 * @param string $after Optional. Display after edit link.
     703 * @param object $term Term object
     704 * @return string HTML content.
     705 */
     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 );
     714    if ( !current_user_can($tax->cap->edit_terms) )
     715        return;
    683716
    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
Note: See TracChangeset for help on using the changeset viewer.