wp_ajax_edit_comment

The timeline below displays how wordpress function wp_ajax_edit_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 editing a comment via AJAX.
 *
 * @since 3.1.0
 */
function wp_ajax_edit_comment()
{
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' === $_POST['content']) {
        wp_die(__('Please type your comment text.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    $updated = edit_comment();
    if (is_wp_error($updated)) {
        wp_die($updated->get_error_message());
    }
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 6.1

/**
 * Ajax handler for editing a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_edit_comment()
{
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' === $_POST['content']) {
        wp_die(__('Please type your comment text.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    $updated = edit_comment();
    if (is_wp_error($updated)) {
        wp_die($updated->get_error_message());
    }
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 5.5

/**
 * Ajax handler for editing a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_edit_comment()
{
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' === $_POST['content']) {
        wp_die(__('Error: Please type your comment text.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    $updated = edit_comment();
    if (is_wp_error($updated)) {
        wp_die($updated->get_error_message());
    }
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 5.4

/**
 * Ajax handler for editing a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_edit_comment()
{
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' == $_POST['content']) {
        wp_die(__('Error: Please type a comment.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    edit_comment();
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 4.7

/**
 * Ajax handler for editing a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_edit_comment()
{
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' == $_POST['content']) {
        wp_die(__('ERROR: please type a comment.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    edit_comment();
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 4.3

/**
 * Ajax handler for editing a comment.
 *
 * @since 3.1.0
 *
 * @global WP_List_Table $wp_list_table
 */
function wp_ajax_edit_comment()
{
    global $wp_list_table;
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' == $_POST['content']) {
        wp_die(__('ERROR: please type a comment.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    edit_comment();
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 4.0

/**
 * Ajax handler for editing a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_edit_comment()
{
    global $wp_list_table;
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' == $_POST['content']) {
        wp_die(__('ERROR: please type a comment.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    edit_comment();
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}

WordPress Version: 3.7

function wp_ajax_edit_comment()
{
    global $wp_list_table;
    check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment');
    $comment_id = (int) $_POST['comment_ID'];
    if (!current_user_can('edit_comment', $comment_id)) {
        wp_die(-1);
    }
    if ('' == $_POST['content']) {
        wp_die(__('ERROR: please type a comment.'));
    }
    if (isset($_POST['status'])) {
        $_POST['comment_status'] = $_POST['status'];
    }
    edit_comment();
    $position = (isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
    $checkbox = (isset($_POST['checkbox']) && true == $_POST['checkbox']) ? 1 : 0;
    $wp_list_table = _get_list_table($checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array('screen' => 'edit-comments'));
    $comment = get_comment($comment_id);
    if (empty($comment->comment_ID)) {
        wp_die(-1);
    }
    ob_start();
    $wp_list_table->single_row($comment);
    $comment_list_item = ob_get_clean();
    $x = new WP_Ajax_Response();
    $x->add(array('what' => 'edit_comment', 'id' => $comment->comment_ID, 'data' => $comment_list_item, 'position' => $position));
    $x->send();
}