Buddypress remove email id from private messages

Add the following code in functions.php of your theme

/*remove email addresses from private messages
http://webdeveloperswall.com/snippets/buddypress-remove-email-id-from-private-messages
*/
function wdw_remove_email_from_private_msg($message){
	$replacement = "[removed]";
	/*if you dont want any replacement text, replace the above line with 
		$replacement = ""; 
	*/
	return preg_replace("/[^@\s]*@[^@\s]*\.[^@\s]*/", $replacement, $message);
	/*the code is short and works in most cases but not full proof. Check http://www.linuxjournal.com/article/9585*/
}
add_filter('messages_message_content_before_save', 'wdw_remove_email_from_private_msg');
add_filter('messages_message_subject_before_save', 'wdw_remove_email_from_private_msg');

It’ll remove all email id’s from message subject and content. While replying(ajax-no postback) the message is displayed to sender unaltered, but don’t panic, it actually is removed and receiver will never see the email id.

Published by

Chandan Chaudhary

Chandan is a WordPress guy. A programmer at heart. He loves building community sites with WordPress and BuddyPress.

3 thoughts on “Buddypress remove email id from private messages”

  1. Happy new year man,

    Just to say that you are amazingly great. i have just tested the snippet and it works great.

    Looking forward to hire you for some custom coding.

Leave a Reply

Your email address will not be published. Required fields are marked *