get_delete_post_link()

git-svn-id: http://svn.automattic.com/wordpress/trunk@11956 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan
2009-09-21 21:33:00 +00:00
parent ef17b0b875
commit 5e4dc4dfd4
2 changed files with 54 additions and 2 deletions

View File

@@ -731,6 +731,58 @@ function edit_post_link( $link = 'Edit This', $before = '', $after = '', $id = 0
echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
}
/**
* Retrieve delete posts link for post.
*
* Can be used within the WordPress loop or outside of it. Can be used with
* pages, posts, attachments, and revisions.
*
* @since 2.9.0
*
* @param int $id Optional. Post ID.
* @param string $context Optional, default to display. How to write the '&', defaults to '&'.
* @return string
*/
function get_delete_post_link($id = 0, $context = 'display') {
if ( !$post = &get_post( $id ) )
return;
if ( 'display' == $context )
$action = 'action=trash&';
else
$action = 'action=trash&';
switch ( $post->post_type ) :
case 'page' :
if ( !current_user_can( 'delete_page', $post->ID ) )
return;
$file = 'page';
$var = 'post';
break;
case 'attachment' :
if ( !current_user_can( 'delete_post', $post->ID ) )
return;
$file = 'media';
$var = 'attachment_id';
break;
case 'revision' :
if ( !current_user_can( 'delete_post', $post->ID ) )
return;
$file = 'revision';
$var = 'revision';
$action = '';
break;
default :
if ( !current_user_can( 'edit_post', $post->ID ) )
return apply_filters( 'get_delete_post_link', '', $post->ID, $context );;
$file = 'post';
$var = 'post';
break;
endswitch;
return apply_filters( 'get_delete_post_link', wp_nonce_url( admin_url("$file.php?{$action}$var=$post->ID"), "trash-{$file}_" . $post->ID ), $context );
}
/**
* Retrieve edit comment link.
*