wp_comments_personal_data_eraser

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

WordPress Version: 6.4

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $email_address The comment author email address.
 * @param int    $page          Comment page number.
 * @return array {
 *     Data removal results.
 *
 *     @type bool     $items_removed  Whether items were actually removed.
 *     @type bool     $items_retained Whether items were retained.
 *     @type string[] $messages       An array of messages to add to the personal data export file.
 *     @type bool     $done           Whether the eraser is finished.
 * }
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'orderby' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string $anon_message       Whether to apply the comment anonymization (bool) or a custom
         *                                        message (string). Default true.
         * @param WP_Comment  $comment            WP_Comment object.
         * @param array       $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID. */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: 6.2

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $email_address The comment author email address.
 * @param int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'orderby' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string $anon_message       Whether to apply the comment anonymization (bool) or a custom
         *                                        message (string). Default true.
         * @param WP_Comment  $comment            WP_Comment object.
         * @param array       $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID. */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: 5.5

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @param string $email_address The comment author email address.
 * @param int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string $anon_message       Whether to apply the comment anonymization (bool) or a custom
         *                                        message (string). Default true.
         * @param WP_Comment  $comment            WP_Comment object.
         * @param array       $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID. */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: 5.4

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @param  string $email_address The comment author email address.
 * @param  int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string $anon_message       Whether to apply the comment anonymization (bool) or a custom
         *                                        message (string). Default true.
         * @param WP_Comment  $comment            WP_Comment object.
         * @param array       $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID. */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: 5.3

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @param  string $email_address The comment author email address.
 * @param  int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string                    Whether to apply the comment anonymization (bool).
         *                                       Custom prevention message (string). Default true.
         * @param WP_Comment $comment            WP_Comment object.
         * @param array      $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID. */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: 9.8

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @param  string $email_address The comment author email address.
 * @param  int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string                    Whether to apply the comment anonymization (bool).
         *                                       Custom prevention message (string). Default true.
         * @param WP_Comment $comment            WP_Comment object.
         * @param array      $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: 9.6

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @param  string $email_address The comment author email address.
 * @param  int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = wp_privacy_anonymize_data('email', $comment->comment_author_email);
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = wp_privacy_anonymize_data('url', $comment->comment_author_url);
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string                    Whether to apply the comment anonymization (bool).
         *                                       Custom prevention message (string). Default true.
         * @param WP_Comment $comment            WP_Comment object.
         * @param array      $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}

WordPress Version: .10

/**
 * Erases personal data associated with an email address from the comments table.
 *
 * @since 4.9.6
 *
 * @param  string $email_address The comment author email address.
 * @param  int    $page          Comment page.
 * @return array
 */
function wp_comments_personal_data_eraser($email_address, $page = 1)
{
    global $wpdb;
    if (empty($email_address)) {
        return array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true);
    }
    // Limit us to 500 comments at a time to avoid timing out.
    $number = 500;
    $page = (int) $page;
    $items_removed = false;
    $items_retained = false;
    $comments = get_comments(array('author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', 'include_unapproved' => true));
    /* translators: Name of a comment's author after being anonymized. */
    $anon_author = __('Anonymous');
    $messages = array();
    foreach ((array) $comments as $comment) {
        $anonymized_comment = array();
        $anonymized_comment['comment_agent'] = '';
        $anonymized_comment['comment_author'] = $anon_author;
        $anonymized_comment['comment_author_email'] = '';
        $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data('ip', $comment->comment_author_IP);
        $anonymized_comment['comment_author_url'] = '';
        $anonymized_comment['user_id'] = 0;
        $comment_id = (int) $comment->comment_ID;
        /**
         * Filters whether to anonymize the comment.
         *
         * @since 4.9.6
         *
         * @param bool|string                    Whether to apply the comment anonymization (bool).
         *                                       Custom prevention message (string). Default true.
         * @param WP_Comment $comment            WP_Comment object.
         * @param array      $anonymized_comment Anonymized comment data.
         */
        $anon_message = apply_filters('wp_anonymize_comment', true, $comment, $anonymized_comment);
        if (true !== $anon_message) {
            if ($anon_message && is_string($anon_message)) {
                $messages[] = esc_html($anon_message);
            } else {
                /* translators: %d: Comment ID */
                $messages[] = sprintf(__('Comment %d contains personal data but could not be anonymized.'), $comment_id);
            }
            $items_retained = true;
            continue;
        }
        $args = array('comment_ID' => $comment_id);
        $updated = $wpdb->update($wpdb->comments, $anonymized_comment, $args);
        if ($updated) {
            $items_removed = true;
            clean_comment_cache($comment_id);
        } else {
            $items_retained = true;
        }
    }
    $done = count($comments) < $number;
    return array('items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done);
}