public function ajax_update_comment($handler_vars)
{
Utils::check_request_method(array('POST'));
$ar = new AjaxResponse();
// check WSSE authentication
$wsse = Utils::WSSE($_POST['nonce'], $_POST['timestamp']);
if ($_POST['digest'] != $wsse['digest']) {
$ar->message = _t('WSSE authentication failed.');
$ar->out();
return;
}
$ids = $_POST['selected'];
if ((!isset($ids) || empty($ids)) && $_POST['action'] == 'delete') {
$ar->message = _t('No comments selected.');
$ar->out();
return;
}
$comments = Comments::get(array('id' => $ids, 'nolimit' => true));
Plugins::act('admin_moderate_comments', $_POST['action'], $comments, $this);
$status_msg = _t('Unknown action "%s"', array($handler_vars['action']));
switch ($_POST['action']) {
case 'delete_spam':
Comments::delete_by_status('spam');
$status_msg = _t('Deleted all spam comments');
break;
case 'delete_unapproved':
Comments::delete_by_status('unapproved');
$status_msg = _t('Deleted all unapproved comments');
break;
case 'delete':
// Comments marked for deletion
Comments::delete_these($comments);
$status_msg = sprintf(_n('Deleted %d comment', 'Deleted %d comments', count($ids)), count($ids));
break;
case 'spam':
// Comments marked as spam
Comments::moderate_these($comments, 'spam');
$status_msg = sprintf(_n('Marked %d comment as spam', 'Marked %d comments as spam', count($ids)), count($ids));
break;
case 'approve':
case 'approved':
// Comments marked for approval
Comments::moderate_these($comments, 'approved');
$status_msg = sprintf(_n('Approved %d comment', 'Approved %d comments', count($ids)), count($ids));
break;
case 'unapprove':
case 'unapproved':
// Comments marked for unapproval
Comments::moderate_these($comments, 'unapproved');
$status_msg = sprintf(_n('Unapproved %d comment', 'Unapproved %d comments', count($ids)), count($ids));
break;
default:
// Specific plugin-supplied action
$status_msg = Plugins::filter('admin_comments_action', $status_msg, $_POST['action'], $comments);
break;
}
$ar->message = $status_msg;
$ar->out();
}