mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-27 10:08:27 +00:00
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:
parent
0bf194de3b
commit
3e3cb817f1
@ -314,8 +314,14 @@ case 'delete-page' :
|
|||||||
die('0');
|
die('0');
|
||||||
break;
|
break;
|
||||||
case 'dim-comment' : // On success, die with time() instead of 1
|
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 ) )
|
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
|
||||||
die('-1');
|
die('-1');
|
||||||
@ -329,14 +335,20 @@ case 'dim-comment' : // On success, die with time() instead of 1
|
|||||||
$r = 0;
|
$r = 0;
|
||||||
if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
|
if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
|
||||||
check_ajax_referer( "approve-comment_$id" );
|
check_ajax_referer( "approve-comment_$id" );
|
||||||
if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
|
$result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
|
||||||
$r = 1;
|
|
||||||
} else {
|
} else {
|
||||||
check_ajax_referer( "unapprove-comment_$id" );
|
check_ajax_referer( "unapprove-comment_$id" );
|
||||||
if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
|
$result = wp_set_comment_status( $comment->comment_ID, 'hold', true );
|
||||||
$r = 1;
|
|
||||||
}
|
}
|
||||||
if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
|
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 );
|
_wp_ajax_delete_comment_response( $comment->comment_ID );
|
||||||
die( '0' );
|
die( '0' );
|
||||||
break;
|
break;
|
||||||
|
@ -1014,9 +1014,10 @@ function wp_new_comment( $commentdata ) {
|
|||||||
*
|
*
|
||||||
* @param int $comment_id Comment ID.
|
* @param int $comment_id Comment ID.
|
||||||
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
|
* @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.
|
* @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;
|
global $wpdb;
|
||||||
|
|
||||||
switch ( $comment_status ) {
|
switch ( $comment_status ) {
|
||||||
@ -1040,8 +1041,12 @@ function wp_set_comment_status($comment_id, $comment_status) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$wpdb->query($query) )
|
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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
clean_comment_cache($comment_id);
|
clean_comment_cache($comment_id);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user