Make WordPress Core

Changeset 5302


Ignore:
Timestamp:
04/24/2007 11:21:56 PM (19 years ago)
Author:
rob1n
Message:

get_edit_*_link() functions. fixes #4153

File:
1 edited

Legend:

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

    r5282 r5302  
    111111
    112112// get permalink from post ID
    113 function post_permalink($post_id = 0, $mode = '') { // $mode legacy
     113function post_permalink($post_id = 0, $deprecated = '') {
    114114        return get_permalink($post_id);
    115115}
     
    275275}
    276276
    277 function edit_post_link($link = 'Edit This', $before = '', $after = '') {
     277function get_edit_post_link( $id = 0 ) {
     278        $post = &get_post( $id );
     279       
     280        if ( $post->post_type == 'attachment' )
     281                return;
     282        elseif ( $post->post_type == 'page' ) {
     283                if ( !current_user_can( 'edit_page', $post->ID ) )
     284                        return;
     285               
     286                $file = 'page';
     287        } else {
     288                if ( !current_user_can( 'edit_post', $post->ID ) )
     289                        return;
     290               
     291                $file = 'post';
     292        }
     293       
     294        return apply_filters( 'get_edit_post_link', get_bloginfo( 'wpurl' ) . '/wp-admin/' . $file . '.php?action=edit&post=' . $post->ID, $post->ID );
     295}
     296
     297function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
    278298        global $post;
    279 
    280         if ( is_attachment() )
     299       
     300        $link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . __( 'Edit post' ) . '">' . $link . '</a>';
     301        echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
     302}
     303
     304function get_edit_comment_link( $comment_id = 0 ) {
     305        $comment = &get_comment( $comment_id );
     306        $post = &get_post( $comment->comment_post_ID );
     307       
     308        if ( $post->post_type == 'attachment' )
    281309                return;
    282 
    283         if( $post->post_type == 'page' ) {
    284                 if ( ! current_user_can('edit_page', $post->ID) )
     310        elseif ( $post->post_type == 'page' )
     311                if ( !current_user_can( 'edit_page', $post->ID ) )
    285312                        return;
    286                 $file = 'page';
    287         } else {
    288                 if ( ! current_user_can('edit_post', $post->ID) )
     313        else
     314                if ( !current_user_can( 'edit_post', $post->ID ) )
    289315                        return;
    290                 $file = 'post';
    291         }
    292 
    293         $location = get_option('siteurl') . "/wp-admin/{$file}.php?action=edit&amp;post=$post->ID";
    294         echo $before . "<a href=\"$location\">$link</a>" . $after;
    295 }
    296 
    297 function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
    298         global $post, $comment;
    299 
    300         if( $post->post_type == 'page' ){
    301                 if ( ! current_user_can('edit_page', $post->ID) )
    302                         return;
    303         } else {
    304                 if ( ! current_user_can('edit_post', $post->ID) )
    305                         return;
    306         }
    307 
    308         $location = get_option('siteurl') . "/wp-admin/comment.php?action=editcomment&amp;c=$comment->comment_ID";
    309         echo $before . "<a href='$location'>$link</a>" . $after;
     316       
     317        $location = get_bloginfo( 'wpurl' ) . '/wp-admin/comment.php?action=editcomment&amp;c=' . $comment->comment_ID;
     318        return apply_filters( 'get_edit_comment_link', $location );
     319}
     320
     321function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
     322        global $comment;
     323       
     324        $link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
     325        echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
    310326}
    311327
Note: See TracChangeset for help on using the changeset viewer.