BuddyDev

Search

[Resolved] Privacy issue in comments

Tagged: ,

  • Participant
    Level: Enlightened
    Posts: 39
    Tiziano on #10836

    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 address

    Is there a way to hide such sensitive datas?

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #10880

    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
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 39
    Tiziano on #10899

    Thank you Brajesh! I’ll try and let you know!

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #10933

    You are welcome. Please do let me know which way did you prefer to do it.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 39
    Tiziano on #11067

    Hi Brajesh, where should I put this code? I’ve tried in functions.php of the theme but it didn’t work.

    Regards
    Tiziano

  • Participant
    Level: Enlightened
    Posts: 39
    Tiziano on #11281

    Dear Brajesh, I’ve choosen second solution as I need users to be notified by email when somebody comment their posts. The problem is that it didn’t work. I’ve putted code in functions. Can you help me please?

    Regards.

    Tiziano

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #11319

    @ravisharma, please look into this topic and assist as needed.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #11334

    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
    Ravi

  • Participant
    Level: Enlightened
    Posts: 39
    Tiziano on #11338

    Dear Ravi, dear Brajesh,

    It works! Is it possible to remove even IP adress?

    Thanks
    Tiziano

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #11340

    Hello 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.

This topic is: resolved