The author_email WordPress PHP filter modifies the comment author’s email address for display.
Usage
add_filter('author_email', 'your_custom_function', 10, 2); function your_custom_function($author_email, $comment_id) { // your custom code here return $author_email; }
Parameters
$author_email
(string) – The comment author’s email address.$comment_id
(string) – The comment ID as a numeric string.
More information
See WordPress Developer Resources: author_email
Examples
Anonymize email addresses
Anonymize the email addresses of comment authors by replacing them with a generic email.
add_filter('author_email', 'anonymize_comment_author_email', 10, 2); function anonymize_comment_author_email($author_email, $comment_id) { return '[email protected]'; }
Add a domain to email addresses
Add a specific domain to email addresses if they don’t already have one.
add_filter('author_email', 'add_domain_to_email', 10, 2); function add_domain_to_email($author_email, $comment_id) { if (!strpos($author_email, '@')) { $author_email .= '@example.com'; } return $author_email; }
Replace specific email addresses
Replace specific email addresses with a custom email.
add_filter('author_email', 'replace_specific_email', 10, 2); function replace_specific_email($author_email, $comment_id) { if ($author_email === '[email protected]') { $author_email = '[email protected]'; } return $author_email; }
Uppercase all email addresses
Convert all email addresses to uppercase.
add_filter('author_email', 'uppercase_email', 10, 2); function uppercase_email($author_email, $comment_id) { return strtoupper($author_email); }
Remove special characters from email addresses
Remove special characters (e.g., ‘+’ and ‘.’) from email addresses.
add_filter('author_email', 'remove_special_chars', 10, 2); function remove_special_chars($author_email, $comment_id) { $author_email = str_replace(['+', '.'], '', $author_email); return $author_email; }