WordPress.org

Make WordPress Core

Changeset 8296


Ignore:
Timestamp:
07/09/2008 02:00:21 AM (12 years ago)
Author:
matt
Message:

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

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r8214 r8296  
    3131    check_ajax_referer( "delete-comment_$id" );
    3232    if ( !$comment = get_comment( $id ) )
    33         die('0');
     33        die('1');
    3434    if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    3535        die('-1');
    3636
    37     if ( isset($_POST['spam']) && 1 == $_POST['spam'] )
     37    if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
     38        if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) )
     39            die('1');
    3840        $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
    39     else
     41    } else {
    4042        $r = wp_delete_comment( $comment->comment_ID );
     43    }
    4144
    4245    die( $r ? '1' : '0' );
     
    4750        die('-1');
    4851
     52    $cat = get_category( $id );
     53    if ( !$cat || is_wp_error( $cat ) )
     54        die('1');
     55
    4956    if ( wp_delete_category( $id ) )
    5057        die('1');
    51     else    die('0');
     58    else
     59        die('0');
    5260    break;
    5361case 'delete-tag' :
     
    5664        die('-1');
    5765
     66    $tag = get_term( $id, 'post_tag' );
     67    if ( !$tag || is_wp_error( $tag ) )
     68        die('1');
     69
    5870    if ( wp_delete_term($id, 'post_tag'))
    5971        die('1');
    60     else    die('0');
     72    else
     73        die('0');
    6174    break;
    6275case 'delete-link-cat' :
     
    6477    if ( !current_user_can( 'manage_categories' ) )
    6578        die('-1');
     79
     80    $cat = get_term( $id, 'link_category' );
     81    if ( !$cat || is_wp_error( $cat ) )
     82        die('1');
    6683
    6784    $cat_name = get_term_field('name', $id, 'link_category');
     
    95112        die('-1');
    96113
     114    $link = get_bookmark( $id );
     115    if ( !$link || is_wp_error( $link ) )
     116        die('1');
     117
    97118    if ( wp_delete_link( $id ) )
    98119        die('1');
    99     else    die('0');
     120    else
     121        die('0');
    100122    break;
    101123case 'delete-meta' :
    102124    check_ajax_referer( "delete-meta_$id" );
    103125    if ( !$meta = get_post_meta_by_id( $id ) )
    104         die('0');
     126        die('1');
     127
    105128    if ( !current_user_can( 'edit_post', $meta->post_id ) )
    106129        die('-1');
     
    114137        die('-1');
    115138
     139    if ( !get_post( $id ) )
     140        die('1');
     141
    116142    if ( wp_delete_post( $id ) )
    117143        die('1');
     
    124150        die('-1');
    125151
     152    if ( !get_page( $id ) )
     153        die('1');
     154
    126155    if ( wp_delete_post( $id ) )
    127156        die('1');
    128     else    die('0');
     157    else
     158        die('0');
    129159    break;
    130160case 'dim-comment' :
    131161    if ( !$comment = get_comment( $id ) )
    132162        die('0');
     163
    133164    if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    134165        die('-1');
     
    136167        die('-1');
    137168
    138     if ( 'unapproved' == wp_get_comment_status($comment->comment_ID) ) {
     169    $current = wp_get_comment_status( $comment->comment_ID );
     170    if ( $_POST['new'] == $current )
     171        die('1');
     172
     173    if ( 'unapproved' == $current ) {
    139174        check_ajax_referer( "approve-comment_$id" );
    140175        if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
  • trunk/wp-admin/includes/template.php

    r8217 r8296  
    769769
    770770    if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
    771         $actions['approve']   = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
    772         $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
     771        $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> | ';
     772        $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> | ';
    773773
    774774        // we're looking at list of only approved or only unapproved comments
    775775        if ( 'moderated' == $comment_status ) {
    776             $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> | ';
     776            $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> | ';
    777777            unset($actions['unapprove']);
    778778        } elseif ( 'approved' == $comment_status ) {
    779             $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> | ';
     779            $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> | ';
    780780            unset($actions['approve']);
    781781        }
Note: See TracChangeset for help on using the changeset viewer.