Ajax Deleting an object that's already been deleted should silently succeed. Hat tip: mdawaffe. Fixes #7264.

git-svn-id: http://svn.automattic.com/wordpress/trunk@8296 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2008-07-09 02:00:21 +00:00
parent 3b48af4a6d
commit 80b1ebdbbf
2 changed files with 48 additions and 13 deletions

View File

@ -30,14 +30,17 @@ switch ( $action = $_POST['action'] ) :
case 'delete-comment' :
check_ajax_referer( "delete-comment_$id" );
if ( !$comment = get_comment( $id ) )
die('0');
die('1');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( isset($_POST['spam']) && 1 == $_POST['spam'] )
if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) )
die('1');
$r = wp_set_comment_status( $comment->comment_ID, 'spam' );
else
} else {
$r = wp_delete_comment( $comment->comment_ID );
}
die( $r ? '1' : '0' );
break;
@ -46,24 +49,38 @@ case 'delete-cat' :
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$cat = get_category( $id );
if ( !$cat || is_wp_error( $cat ) )
die('1');
if ( wp_delete_category( $id ) )
die('1');
else die('0');
else
die('0');
break;
case 'delete-tag' :
check_ajax_referer( "delete-tag_$id" );
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$tag = get_term( $id, 'post_tag' );
if ( !$tag || is_wp_error( $tag ) )
die('1');
if ( wp_delete_term($id, 'post_tag'))
die('1');
else die('0');
else
die('0');
break;
case 'delete-link-cat' :
check_ajax_referer( "delete-link-category_$id" );
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$cat = get_term( $id, 'link_category' );
if ( !$cat || is_wp_error( $cat ) )
die('1');
$cat_name = get_term_field('name', $id, 'link_category');
// Don't delete the default cats.
@ -94,14 +111,20 @@ case 'delete-link' :
if ( !current_user_can( 'manage_links' ) )
die('-1');
$link = get_bookmark( $id );
if ( !$link || is_wp_error( $link ) )
die('1');
if ( wp_delete_link( $id ) )
die('1');
else die('0');
else
die('0');
break;
case 'delete-meta' :
check_ajax_referer( "delete-meta_$id" );
if ( !$meta = get_post_meta_by_id( $id ) )
die('0');
die('1');
if ( !current_user_can( 'edit_post', $meta->post_id ) )
die('-1');
if ( delete_meta( $meta->meta_id ) )
@ -113,6 +136,9 @@ case 'delete-post' :
if ( !current_user_can( 'delete_post', $id ) )
die('-1');
if ( !get_post( $id ) )
die('1');
if ( wp_delete_post( $id ) )
die('1');
else
@ -123,19 +149,28 @@ case 'delete-page' :
if ( !current_user_can( 'delete_page', $id ) )
die('-1');
if ( !get_page( $id ) )
die('1');
if ( wp_delete_post( $id ) )
die('1');
else die('0');
else
die('0');
break;
case 'dim-comment' :
if ( !$comment = get_comment( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( !current_user_can( 'moderate_comments' ) )
die('-1');
if ( 'unapproved' == wp_get_comment_status($comment->comment_ID) ) {
$current = wp_get_comment_status( $comment->comment_ID );
if ( $_POST['new'] == $current )
die('1');
if ( 'unapproved' == $current ) {
check_ajax_referer( "approve-comment_$id" );
if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
die('1');

View File

@ -768,15 +768,15 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true
$actions = array();
if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
$actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
$actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
$actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
$actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
// we're looking at list of only approved or only unapproved comments
if ( 'moderated' == $comment_status ) {
$actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
$actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
unset($actions['unapprove']);
} elseif ( 'approved' == $comment_status ) {
$actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
$actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
unset($actions['approve']);
}