Reply to Commenters From Moderation Emails
Adds the commenter's email as the Reply-To of comment moderation emails, so you can answer or ask a question just by pressing Reply in your inbox.
Opens WPIDE on
Code
add_filter( 'comment_moderation_headers', function ( $headers, $comment_id ) {
$comment = get_comment( $comment_id );
if ( ! $comment || ! is_email( $comment->comment_author_email ) || false !== stripos( (string) $headers, 'Reply-To:' ) ) {
return $headers;
}
$name = trim( str_replace( array( '"', "\r", "\n", '<', '>' ), '', $comment->comment_author ) );
return rtrim( (string) $headers, "\n" ) . "\nReply-To: " . ( $name ? '"' . $name . '" ' : '' ) . '<' . $comment->comment_author_email . ">\n";
}, 10, 2 );
Notes
WordPress already does this for post author notifications; this adds it to the "please moderate" emails.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.