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

git-svn-id: http://svn.automattic.com/wordpress/trunk@10681 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-03-02 21:48:37 +00:00
parent 0bf194de3b
commit 3e3cb817f1
2 changed files with 28 additions and 11 deletions

View File

@ -314,8 +314,14 @@ case 'delete-page' :
die('0');
break;
case 'dim-comment' : // On success, die with time() instead of 1
if ( !$comment = get_comment( $id ) )
die('0');
if ( !$comment = get_comment( $id ) ) {
$x = new WP_Ajax_Response( array(
'what' => 'comment',
'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))
) );
$x->send();
}
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
@ -329,15 +335,21 @@ case 'dim-comment' : // On success, die with time() instead of 1
$r = 0;
if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
check_ajax_referer( "approve-comment_$id" );
if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
$r = 1;
$result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
} else {
check_ajax_referer( "unapprove-comment_$id" );
if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
$r = 1;
$result = wp_set_comment_status( $comment->comment_ID, 'hold', true );
}
if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
_wp_ajax_delete_comment_response( $comment->comment_ID );
if ( is_wp_error($result) ) {
$x = new WP_Ajax_Response( array(
'what' => 'comment',
'id' => $result
) );
$x->send();
}
// Decide if we need to send back '1' or a more complicated response including page links and comment counts
_wp_ajax_delete_comment_response( $comment->comment_ID );
die( '0' );
break;
case 'add-category' : // On the Fly

View File

@ -1014,9 +1014,10 @@ function wp_new_comment( $commentdata ) {
*
* @param int $comment_id Comment ID.
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
* @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
* @return bool False on failure or deletion and true on success.
*/
function wp_set_comment_status($comment_id, $comment_status) {
function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
global $wpdb;
switch ( $comment_status ) {
@ -1040,8 +1041,12 @@ function wp_set_comment_status($comment_id, $comment_status) {
return false;
}
if ( !$wpdb->query($query) )
return false;
if ( !$wpdb->query($query) ) {
if ( $wp_error )
return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error);
else
return false;
}
clean_comment_cache($comment_id);