BuddyPress / Multisite Notification plugin similar to FaceBook

We all love how Facebook notifies its users on the notification received for various activities such as messages, comments, friend request, etc.

Notification is displayed on the Browser title tab with a number. It makes sure that user is brought back to the website to check out that notification (Trust me – From SEO point of view, it helps alot to keep user on the website).

BuddyPress core has been missing out on this important feature for a while.

FB like notification for buddypress is one such plugin which solves the purpose & gives us notification just like FaceBook in real-time. More-over, it works fine on Multi-site too.

Here are few features of the plugin listed down for you:

  • Real-time notification for BuddyPress / Multi-site
  • Notification for adding friend, receiving messages, comments, groups. In short, everything which BuddyPress covers under notification bar.
  • Works same as Facebook Notification.  (Screenshot attached)buddypress-fb-like-notification

 

  • BuddyPress Notification plugin updates browser window title even if user is away.

The plugin repeatedly checks for new notifications for the loggedin user and if any new notification is found, it does 2 things:

1) Updates the browser window title( e.g: ‘members|mydomain.com’ becomes ‘(2) members|mydomain.com’ ) and blinks/switches repeatedly between the old and new title

2) Updates the notification menu:

– adds new notification(if any) items to the list

– updates the existing ones(if any). E.g: from ‘You have 1 new message’ to ‘You have 2 new messages’

 

Hope you like the post. Comments are entertained as well 🙂

Use the plugin by using the below “Download” button.


Load more activities on scroll

Modify your buddypress theme to load more activity posts when user scrolls down!
All you need to do is to add the following javascript in any of your javascript files (and make sure that javascript file is included! lol). The script loads more content by ajax and appends at the bottom of the page. The server side code to process the ajax request is already there in buddypress. God bless those guys at automattic!

That’s it here.

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.

Buddypress – Check if a user is online

Buddypress function/code to check if a user is online.
You can use this function to check if a given buddypress user is online.

The function:

Add following code into your functions.php file:

<?php 
/**
* http://webdeveloperswall.com/buddypress/check-if-a-user-is-online
**/
function is_user_online($user_id, $time=5){
	global $wp, $wpdb;
	
	$user_login = $wpdb->get_var( $wpdb->prepare( "
		SELECT u.user_login FROM $wpdb->users u JOIN $wpdb->usermeta um ON um.user_id = u.ID 
		WHERE 	u.ID = $user_id 
		AND um.meta_key = 'last_activity'
		AND DATE_ADD( um.meta_value, INTERVAL $time MINUTE ) >= UTC_TIMESTAMP()
		" 	
	));
	if(isset($user_login) && $user_login !=""){
		return true;
	}
	else {return false;}
}
?>

Usage :

The function takes a user id as input and return a boolean value of true/false indicating user is online/offline respectively.
A simple use:

<?php
if(is_user_online(3)){
	echo "user id 3 is online";
}
else{
	echo "user id 3 is offline";
}
?>

Basically, by default it checks if the said user is active in last 5 minutes or not.
The function takes second optional argument time.

<?php
if(is_user_online(3, 10)){
	echo "user id 3 is active in last 10 minutes";
}
else{
	echo "user id 3 is inactive since last 10 minutes";
}
?>

The above code checks if the user is active since last 10 minutes or not.

That’s it in here. Hope you find it helpful.