Ejemplo n.º 1
0
             $approved++;
             break;
         case 'unapprove':
             nxt_set_comment_status($comment_id, 'hold');
             $unapproved++;
             break;
         case 'spam':
             nxt_spam_comment($comment_id);
             $spammed++;
             break;
         case 'unspam':
             nxt_unspam_comment($comment_id);
             $unspammed++;
             break;
         case 'trash':
             nxt_trash_comment($comment_id);
             $trashed++;
             break;
         case 'untrash':
             nxt_untrash_comment($comment_id);
             $untrashed++;
             break;
         case 'delete':
             nxt_delete_comment($comment_id);
             $deleted++;
             break;
     }
 }
 if ($approved) {
     $redirect_to = add_query_arg('approved', $approved, $redirect_to);
 }
Ejemplo n.º 2
0
 case 'delete-comment':
     // On success, die with time() instead of 1
     if (!($comment = get_comment($id))) {
         die((string) time());
     }
     if (!current_user_can('edit_comment', $comment->comment_ID)) {
         die('-1');
     }
     check_ajax_referer("delete-comment_{$id}");
     $status = nxt_get_comment_status($comment->comment_ID);
     $delta = -1;
     if (isset($_POST['trash']) && 1 == $_POST['trash']) {
         if ('trash' == $status) {
             die((string) time());
         }
         $r = nxt_trash_comment($comment->comment_ID);
     } elseif (isset($_POST['untrash']) && 1 == $_POST['untrash']) {
         if ('trash' != $status) {
             die((string) time());
         }
         $r = nxt_untrash_comment($comment->comment_ID);
         if (!isset($_POST['comment_status']) || $_POST['comment_status'] != 'trash') {
             // undo trash, not in trash
             $delta = 1;
         }
     } elseif (isset($_POST['spam']) && 1 == $_POST['spam']) {
         if ('spam' == $status) {
             die((string) time());
         }
         $r = nxt_spam_comment($comment->comment_ID);
     } elseif (isset($_POST['unspam']) && 1 == $_POST['unspam']) {
Ejemplo n.º 3
0
/**
 * Trashes or deletes a comment.
 *
 * The comment is moved to trash instead of permanently deleted unless trash is
 * disabled, item is already in the trash, or $force_delete is true.
 *
 * The post comment count will be updated if the comment was approved and has a
 * post ID available.
 *
 * @since 2.0.0
 * @uses $nxtdb
 * @uses do_action() Calls 'delete_comment' hook on comment ID
 * @uses do_action() Calls 'deleted_comment' hook on comment ID after deletion, on success
 * @uses do_action() Calls 'nxt_set_comment_status' hook on comment ID with 'delete' set for the second parameter
 * @uses nxt_transition_comment_status() Passes new and old comment status along with $comment object
 *
 * @param int $comment_id Comment ID
 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
 * @return bool False if delete comment query failure, true on success.
 */
function nxt_delete_comment($comment_id, $force_delete = false)
{
    global $nxtdb;
    if (!($comment = get_comment($comment_id))) {
        return false;
    }
    if (!$force_delete && EMPTY_TRASH_DAYS && !in_array(nxt_get_comment_status($comment_id), array('trash', 'spam'))) {
        return nxt_trash_comment($comment_id);
    }
    do_action('delete_comment', $comment_id);
    // Move children up a level.
    $children = $nxtdb->get_col($nxtdb->prepare("SELECT comment_ID FROM {$nxtdb->comments} WHERE comment_parent = %d", $comment_id));
    if (!empty($children)) {
        $nxtdb->update($nxtdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment_id));
        clean_comment_cache($children);
    }
    // Delete metadata
    $meta_ids = $nxtdb->get_col($nxtdb->prepare("SELECT meta_id FROM {$nxtdb->commentmeta} WHERE comment_id = %d ", $comment_id));
    if (!empty($meta_ids)) {
        do_action('delete_commentmeta', $meta_ids);
        $in_meta_ids = "'" . implode("', '", $meta_ids) . "'";
        $nxtdb->query("DELETE FROM {$nxtdb->commentmeta} WHERE meta_id IN ({$in_meta_ids})");
        do_action('deleted_commentmeta', $meta_ids);
    }
    if (!$nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->comments} WHERE comment_ID = %d LIMIT 1", $comment_id))) {
        return false;
    }
    do_action('deleted_comment', $comment_id);
    $post_id = $comment->comment_post_ID;
    if ($post_id && $comment->comment_approved == 1) {
        nxt_update_comment_count($post_id);
    }
    clean_comment_cache($comment_id);
    do_action('nxt_set_comment_status', $comment_id, 'delete');
    nxt_transition_comment_status('delete', $comment->comment_approved, $comment);
    return true;
}