wp_untrash_post_comments

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

WordPress Version: 6.5

/**
 * Restores comments for a post from the Trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (!$statuses) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Confidence check. This shouldn't happen.
        if ('post-trashed' === $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 6.1

/**
 * Restores comments for a post from the Trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (!$statuses) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' === $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 5.6

/**
 * Restore comments for a post from the Trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (!$statuses) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' === $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 5.5

/**
 * Restore comments for a post from the Trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' === $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 5.4

/**
 * Restore comments for a post from the Trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the Trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 4.4

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 4.3

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
 * @return true|void
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .30

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 2.3

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .20

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 2.2

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .10

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 4.2

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 1.7

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 1.5

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .40

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 1.4

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .30

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 1.3

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .20

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 1.2

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .10

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 4.1

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return null|bool Null on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 0.7

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 0.4

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .30

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 0.3

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .20

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 0.2

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .10

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 4.0

/**
 * Restore comments for a post from the trash.
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
 * @return mixed False on failure.
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status.
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 9.8

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 9.2

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .10

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 3.9

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    /**
     * Fires before comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    /**
     * Fires after comments are restored for a post from the trash.
     *
     * @since 2.9.0
     *
     * @param int $post_id Post ID.
     */
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 8.4

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .30

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 8.3

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .20

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 8.2

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .10

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 7.5

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .40

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 7.4

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .30

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 7.3

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .20

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 7.2

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: .10

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode(', ', array_map('intval', $comments));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = %s WHERE comment_ID IN ({$comments_in})", $status));
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}

WordPress Version: 3.7

/**
 * Restore comments for a post from the trash
 *
 * @since 2.9.0
 * @uses do_action() on 'untrash_post_comments' before trashing
 * @uses do_action() on 'untrashed_post_comments' after trashing
 *
 * @param int|object $post Post ID or object.
 * @return mixed False on failure
 */
function wp_untrash_post_comments($post = null)
{
    global $wpdb;
    $post = get_post($post);
    if (empty($post)) {
        return;
    }
    $post_id = $post->ID;
    $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    if (empty($statuses)) {
        return true;
    }
    do_action('untrash_post_comments', $post_id);
    // Restore each comment to its original status
    $group_by_status = array();
    foreach ($statuses as $comment_id => $comment_status) {
        $group_by_status[$comment_status][] = $comment_id;
    }
    foreach ($group_by_status as $status => $comments) {
        // Sanity check. This shouldn't happen.
        if ('post-trashed' == $status) {
            $status = '0';
        }
        $comments_in = implode("', '", $comments);
        $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = '{$status}' WHERE comment_ID IN ('" . $comments_in . "')");
    }
    clean_comment_cache(array_keys($statuses));
    delete_post_meta($post_id, '_wp_trash_meta_comments_status');
    do_action('untrashed_post_comments', $post_id);
}