WordPress.org

Make WordPress Core

Changeset 10681


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

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

Location:
trunk
Files:
2 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;
  • trunk/wp-includes/comment.php

    r10579 r10681  
    10151015 * @param int $comment_id Comment ID.
    10161016 * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
     1017 * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
    10171018 * @return bool False on failure or deletion and true on success.
    10181019 */
    1019 function wp_set_comment_status($comment_id, $comment_status) {
     1020function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
    10201021    global $wpdb;
    10211022
     
    10411042    }
    10421043
    1043     if ( !$wpdb->query($query) )
    1044         return false;
     1044    if ( !$wpdb->query($query) ) {
     1045        if ( $wp_error )
     1046            return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error);
     1047        else
     1048            return false;
     1049    }
    10451050
    10461051    clean_comment_cache($comment_id);
Note: See TracChangeset for help on using the changeset viewer.