Title: wp_comments_personal_data_eraser
Published: October 5, 2018
Last modified: May 20, 2026

---

# wp_comments_personal_data_eraser( string $email_address, int $page = 1 ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#wp--skip-link--target)

Erases personal data associated with an email address from the comments table.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#parameters)󠁿

 `$email_address`stringrequired

The comment author email address.

`$page`intoptional

Comment page number.

Default:`1`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#return)󠁿

 array Data removal results.

 * `items_removed` bool
 * Whether items were actually removed.
 * `items_retained` bool
 * Whether items were retained.
 * `messages` string[]
 * An array of messages to add to the personal data export file.
 * `done` bool
 * Whether the eraser is finished.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#source)󠁿

    ```php
    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,
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/comment.php#L3971)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/comment.php#L3971-L4062)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_anonymize_comment’, bool|string $anon_message, WP_Comment $comment, array $anonymized_comment )](https://developer.wordpress.org/reference/hooks/wp_anonymize_comment/)

Filters whether to anonymize the comment.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_privacy_anonymize_data()](https://developer.wordpress.org/reference/functions/wp_privacy_anonymize_data/)`wp-includes/functions.php` |

Returns uniform “anonymous” data by type.

  | 
| [wpdb::update()](https://developer.wordpress.org/reference/classes/wpdb/update/)`wp-includes/class-wpdb.php` |

Updates a row in the table.

  | 
| [clean_comment_cache()](https://developer.wordpress.org/reference/functions/clean_comment_cache/)`wp-includes/comment.php` |

Removes a comment from the object cache.

  | 
| [get_comments()](https://developer.wordpress.org/reference/functions/get_comments/)`wp-includes/comment.php` |

Retrieves a list of comments.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_comments_personal_data_eraser/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_comments_personal_data_eraser%2F)
before being able to contribute a note or feedback.