Hello, when a user publish a post and another user write a comment to this post, the author is notified by an email. This email contains the message itself plus some private details like:
1. email address
2. ip addressIs there a way to hide such sensitive datas?
Thanks
Hi Tiziano,
My apologies.It’s the way WordPress handles comment. There are two ways.
1. Completely disable email to post authors
add_filter( 'notify_post_author', '__return_false' );
That is a bad way.
2. Filtering on ‘comment_notification_text’ like this
function buddydev_strip_commenter_email( $message, $comment_id ) { $comment = get_comment( $comment_id ); $email_info = sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; $message = str_replace( $email_info, '', $message ); return $message; } add_filter( 'comment_notification_text', 'buddydev_strip_commenter_email', 10, 2 );
The second option may work or may not work. It depends on the kind of setup you have.
Please give that a try and let me know.
Regards
BrajeshYou are welcome. Please do let me know which way did you prefer to do it.
Regards
Brajesh@ravisharma, please look into this topic and assist as needed.
Hello Tiziano,
I Have tested the code from theme functions file and it is working. As no email info is going to post author notifying email. Please try to test this code from the default WordPress theme functions file and make sure all plugins are deactivated. Let me know if the code works or not.
Thank You
RaviHello Tiziano,
I am glad that code works. To replace the IP address replace the old code with the following code.
function buddydev_strip_commenter_email( $message, $comment_id ) { $comment = get_comment( $comment_id ); $email_info = sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); $author_ip = sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; $message = str_replace( $email_info, '', $message ); $message = str_replace( $author_ip, 'Author: ' . $comment->comment_author . "\r\n", $message ); return $message; } add_filter( 'comment_notification_text', 'buddydev_strip_commenter_email', 10, 2 );
Thank You
Ravi
The topic ‘ [Resolved] Privacy issue in comments’ is closed to new replies.