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

@ -1450,7 +1450,7 @@ function _post_row($a_post, $pending_comments, $mode) {
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
}
if ( current_user_can('delete_post', $post->ID) ) {
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID) . "'>" . __('Trash') . "</a>";
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash') . "</a>";
}
if ( in_array($post->post_status, array('pending', 'draft')) ) {
if ( current_user_can('edit_post', $post->ID) )
@ -1670,7 +1670,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
$actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
}
if ( current_user_can('delete_page', $page->ID) ) {
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . wp_nonce_url("page.php?action=trash&amp;post=$page->ID", 'trash-page_' . $page->ID) . "'>" . __('Trash') . "</a>";
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . get_delete_post_link($page->ID) . "'>" . __('Trash') . "</a>";
}
if ( in_array($post->post_status, array('pending', 'draft')) ) {
if ( current_user_can('edit_page', $page->ID) )

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 '&amp;'.
* @return string
*/
function get_delete_post_link($id = 0, $context = 'display') {
if ( !$post = &get_post( $id ) )
return;
if ( 'display' == $context )
$action = 'action=trash&amp;';
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.
*