wp_ajax_dim_comment

The timeline below displays how wordpress function wp_ajax_dim_comment has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Handles dimming a comment via AJAX.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    $comment = get_comment($id);
    if (!$comment) {
        $x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error(
            'invalid_comment',
            /* translators: %d: Comment ID. */
            sprintf(__('Comment %d does not exist'), $id)
        )));
        $x->send();
    }
    if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'), true)) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 5.5

/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    $comment = get_comment($id);
    if (!$comment) {
        $x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error(
            'invalid_comment',
            /* translators: %d: Comment ID. */
            sprintf(__('Comment %d does not exist'), $id)
        )));
        $x->send();
    }
    if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'), true)) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 5.4

/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    $comment = get_comment($id);
    if (!$comment) {
        $x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error(
            'invalid_comment',
            /* translators: %d: Comment ID. */
            sprintf(__('Comment %d does not exist'), $id)
        )));
        $x->send();
    }
    if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 5.3

/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    $comment = get_comment($id);
    if (!$comment) {
        $x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error(
            'invalid_comment',
            /* translators: %d: Comment ID. */
            sprintf(__('Comment %d does not exist'), $id)
        )));
        $x->send();
    }
    if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 5.1

/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    if (!$comment = get_comment($id)) {
        $x = new WP_Ajax_Response(array(
            'what' => 'comment',
            /* translators: %d: comment ID */
            'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id)),
        ));
        $x->send();
    }
    if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 4.4

/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 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_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 4.0

/**
 * Ajax handler to dim a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 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_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment->comment_ID);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment->comment_ID, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment->comment_ID, 'hold', true);
    }
    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_die(0);
}

WordPress Version: 3.7

function wp_ajax_dim_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 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_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
        wp_die(-1);
    }
    $current = wp_get_comment_status($comment->comment_ID);
    if (isset($_POST['new']) && $_POST['new'] == $current) {
        wp_die(time());
    }
    check_ajax_referer("approve-comment_{$id}");
    if (in_array($current, array('unapproved', 'spam'))) {
        $result = wp_set_comment_status($comment->comment_ID, 'approve', true);
    } else {
        $result = wp_set_comment_status($comment->comment_ID, 'hold', true);
    }
    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_die(0);
}