Make WordPress Core


Ignore:
Timestamp:
03/02/2009 09:48:37 PM (18 years ago)
Author:
ryan
Message:

Add some error feedback to ajax comment moderation. see #9261

File:
1 edited

Legend:

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

    r10641 r10681  
    315315        break;
    316316case 'dim-comment' : // On success, die with time() instead of 1
    317         if ( !$comment = get_comment( $id ) )
    318                 die('0');
     317
     318        if ( !$comment = get_comment( $id ) ) {
     319                $x = new WP_Ajax_Response( array(
     320                        'what' => 'comment',
     321                        'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))
     322                ) );
     323                $x->send();
     324        }
    319325
    320326        if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
     
    330336        if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
    331337                check_ajax_referer( "approve-comment_$id" );
    332                 if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
    333                         $r = 1;
     338                $result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
    334339        } else {
    335340                check_ajax_referer( "unapprove-comment_$id" );
    336                 if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
    337                         $r = 1;
    338         }
    339         if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    340                 _wp_ajax_delete_comment_response( $comment->comment_ID );
     341                $result = wp_set_comment_status( $comment->comment_ID, 'hold', true );
     342        }
     343        if ( is_wp_error($result) ) {
     344                $x = new WP_Ajax_Response( array(
     345                        'what' => 'comment',
     346                        'id' => $result
     347                ) );
     348                $x->send();
     349        }
     350
     351        // Decide if we need to send back '1' or a more complicated response including page links and comment counts
     352        _wp_ajax_delete_comment_response( $comment->comment_ID );
    341353        die( '0' );
    342354        break;
Note: See TracChangeset for help on using the changeset viewer.