Javascript recursion example

Everyone loves(or should i say ‘gets intimidated by’?) Recursion. But it can be confusing to begin with. So here’s an example of recursion ( in javascript ) to show how recursion can be used to solve real problems in real projects 😉 . The code below is an altered code from one of my projects. Although its in javascript, the basic principle is same and can be easily reproduced in any other language of your choice.

Hope it helps..

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.