Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Function to check if group has notifications

@danbp

Participant

hi ouegy,

Add this snippet to your child-theme functions.php and give it a try.

First function grabs the notification
Second function allows to add a hook to the template (in your case sidebar.php)
And the hook to use.

function bpfr_sidebar_notifications_menu() {
global $bp;

    // if user is not logged, we do nothing
	if ( !is_user_logged_in() )
	return false;

	// if user is group member, show him notification + count
	if ( groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) && $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { 

		echo '<ul>';

		$counter = 0;
			for ( $i = 0; $i < count($notifications); $i++ ) {
			$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 

			echo '<li ="'.$alt.'"><i class="fa fa-group"></i>'. $notifications[$i] .'</li>';

			$counter++;
			echo '</ul>';
			}	
	}
}

function bpfr_xtra_group_sidebar() {	
	// show notification only on the group sidebar
	if(bp_is_groups_component() ):
	// your content
		 bpfr_sidebar_notifications_menu();
	endif;

}
add_action( 'xtragroup', 'bpfr_xtra_group_sidebar' );

The hook to add to sidebar.php (or any other template)
<?php do_action( 'xtragroup' ); ?>

Hope this help ! 😉

Skip to toolbar