edit_comment

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

WordPress Version: 6.1

/**
 * Updates a comment with values provided in $_POST.
 *
 * @since 2.0.0
 * @since 5.5.0 A return value was added.
 *
 * @return int|WP_Error The value 1 if the comment was updated, 0 if not updated.
 *                      A WP_Error object on failure.
 */
function edit_comment()
{
    if (!current_user_can('edit_comment', (int) $_POST['comment_ID'])) {
        wp_die(__('Sorry, you are not allowed to edit comments on this post.'));
    }
    if (isset($_POST['newcomment_author'])) {
        $_POST['comment_author'] = $_POST['newcomment_author'];
    }
    if (isset($_POST['newcomment_author_email'])) {
        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    }
    if (isset($_POST['newcomment_author_url'])) {
        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    }
    if (isset($_POST['comment_status'])) {
        $_POST['comment_approved'] = $_POST['comment_status'];
    }
    if (isset($_POST['content'])) {
        $_POST['comment_content'] = $_POST['content'];
    }
    if (isset($_POST['comment_ID'])) {
        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    }
    foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
        if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] !== $_POST[$timeunit]) {
            $_POST['edit_date'] = '1';
            break;
        }
    }
    if (!empty($_POST['edit_date'])) {
        $aa = $_POST['aa'];
        $mm = $_POST['mm'];
        $jj = $_POST['jj'];
        $hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = ($jj > 31) ? 31 : $jj;
        $hh = ($hh > 23) ? $hh - 24 : $hh;
        $mn = ($mn > 59) ? $mn - 60 : $mn;
        $ss = ($ss > 59) ? $ss - 60 : $ss;
        $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}";
    }
    return wp_update_comment($_POST, true);
}

WordPress Version: 5.8

/**
 * Update a comment with values provided in $_POST.
 *
 * @since 2.0.0
 * @since 5.5.0 A return value was added.
 *
 * @return int|WP_Error The value 1 if the comment was updated, 0 if not updated.
 *                      A WP_Error object on failure.
 */
function edit_comment()
{
    if (!current_user_can('edit_comment', (int) $_POST['comment_ID'])) {
        wp_die(__('Sorry, you are not allowed to edit comments on this post.'));
    }
    if (isset($_POST['newcomment_author'])) {
        $_POST['comment_author'] = $_POST['newcomment_author'];
    }
    if (isset($_POST['newcomment_author_email'])) {
        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    }
    if (isset($_POST['newcomment_author_url'])) {
        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    }
    if (isset($_POST['comment_status'])) {
        $_POST['comment_approved'] = $_POST['comment_status'];
    }
    if (isset($_POST['content'])) {
        $_POST['comment_content'] = $_POST['content'];
    }
    if (isset($_POST['comment_ID'])) {
        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    }
    foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
        if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] !== $_POST[$timeunit]) {
            $_POST['edit_date'] = '1';
            break;
        }
    }
    if (!empty($_POST['edit_date'])) {
        $aa = $_POST['aa'];
        $mm = $_POST['mm'];
        $jj = $_POST['jj'];
        $hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = ($jj > 31) ? 31 : $jj;
        $hh = ($hh > 23) ? $hh - 24 : $hh;
        $mn = ($mn > 59) ? $mn - 60 : $mn;
        $ss = ($ss > 59) ? $ss - 60 : $ss;
        $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}";
    }
    return wp_update_comment($_POST, true);
}

WordPress Version: 5.5

/**
 * Update a comment with values provided in $_POST.
 *
 * @since 2.0.0
 * @since 5.5.0 A return value was added.
 *
 * @return int|WP_Error The value 1 if the comment was updated, 0 if not updated.
 *                      A WP_Error object on failure.
 */
function edit_comment()
{
    if (!current_user_can('edit_comment', (int) $_POST['comment_ID'])) {
        wp_die(__('Sorry, you are not allowed to edit comments on this post.'));
    }
    if (isset($_POST['newcomment_author'])) {
        $_POST['comment_author'] = $_POST['newcomment_author'];
    }
    if (isset($_POST['newcomment_author_email'])) {
        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    }
    if (isset($_POST['newcomment_author_url'])) {
        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    }
    if (isset($_POST['comment_status'])) {
        $_POST['comment_approved'] = $_POST['comment_status'];
    }
    if (isset($_POST['content'])) {
        $_POST['comment_content'] = $_POST['content'];
    }
    if (isset($_POST['comment_ID'])) {
        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    }
    foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
        if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit]) {
            $_POST['edit_date'] = '1';
            break;
        }
    }
    if (!empty($_POST['edit_date'])) {
        $aa = $_POST['aa'];
        $mm = $_POST['mm'];
        $jj = $_POST['jj'];
        $hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = ($jj > 31) ? 31 : $jj;
        $hh = ($hh > 23) ? $hh - 24 : $hh;
        $mn = ($mn > 59) ? $mn - 60 : $mn;
        $ss = ($ss > 59) ? $ss - 60 : $ss;
        $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}";
    }
    return wp_update_comment($_POST, true);
}

WordPress Version: 4.6

/**
 * Update a comment with values provided in $_POST.
 *
 * @since 2.0.0
 */
function edit_comment()
{
    if (!current_user_can('edit_comment', (int) $_POST['comment_ID'])) {
        wp_die(__('Sorry, you are not allowed to edit comments on this post.'));
    }
    if (isset($_POST['newcomment_author'])) {
        $_POST['comment_author'] = $_POST['newcomment_author'];
    }
    if (isset($_POST['newcomment_author_email'])) {
        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    }
    if (isset($_POST['newcomment_author_url'])) {
        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    }
    if (isset($_POST['comment_status'])) {
        $_POST['comment_approved'] = $_POST['comment_status'];
    }
    if (isset($_POST['content'])) {
        $_POST['comment_content'] = $_POST['content'];
    }
    if (isset($_POST['comment_ID'])) {
        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    }
    foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
        if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit]) {
            $_POST['edit_date'] = '1';
            break;
        }
    }
    if (!empty($_POST['edit_date'])) {
        $aa = $_POST['aa'];
        $mm = $_POST['mm'];
        $jj = $_POST['jj'];
        $hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = ($jj > 31) ? 31 : $jj;
        $hh = ($hh > 23) ? $hh - 24 : $hh;
        $mn = ($mn > 59) ? $mn - 60 : $mn;
        $ss = ($ss > 59) ? $ss - 60 : $ss;
        $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}";
    }
    wp_update_comment($_POST);
}

WordPress Version: 3.7

/**
 * Update a comment with values provided in $_POST.
 *
 * @since 2.0.0
 */
function edit_comment()
{
    if (!current_user_can('edit_comment', (int) $_POST['comment_ID'])) {
        wp_die(__('You are not allowed to edit comments on this post.'));
    }
    if (isset($_POST['newcomment_author'])) {
        $_POST['comment_author'] = $_POST['newcomment_author'];
    }
    if (isset($_POST['newcomment_author_email'])) {
        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    }
    if (isset($_POST['newcomment_author_url'])) {
        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    }
    if (isset($_POST['comment_status'])) {
        $_POST['comment_approved'] = $_POST['comment_status'];
    }
    if (isset($_POST['content'])) {
        $_POST['comment_content'] = $_POST['content'];
    }
    if (isset($_POST['comment_ID'])) {
        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    }
    foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
        if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit]) {
            $_POST['edit_date'] = '1';
            break;
        }
    }
    if (!empty($_POST['edit_date'])) {
        $aa = $_POST['aa'];
        $mm = $_POST['mm'];
        $jj = $_POST['jj'];
        $hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = ($jj > 31) ? 31 : $jj;
        $hh = ($hh > 23) ? $hh - 24 : $hh;
        $mn = ($mn > 59) ? $mn - 60 : $mn;
        $ss = ($ss > 59) ? $ss - 60 : $ss;
        $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}";
    }
    wp_update_comment($_POST);
}