Two snippets to do this (hopefully). The first has a fixed position (latest by default), the second let’s you choose the position.
function my_nav_menu_notif_counter($menu) {
if (!is_user_logged_in())
return $menu;
else
$notif = '<li>Notif '. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</li>';
$menu = $menu . $notif;
return $menu;
}
add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
See comment how to apply a position
function my_nav_menu_positioned_notif_counter( $items, $args )
{
if( $args->theme_location == 'primary' ) // only for primary menu
{
$items_array = array();
while ( false !== ( $item_pos = strpos ( $items, '<li', 3) ) )
{
$items_array[] = substr($items, 0, $item_pos);
$items = substr($items, $item_pos);
}
$items_array[] = $items;
array_splice($items_array, 0, 0, '<li>Notif '. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</li>'); // 0,0 is first position, 1,0 is second, etc
$items = implode('', $items_array);
}
return $items;
}
add_filter('wp_nav_menu_items','my_nav_menu_positioned_notif_counter', 10, 2);
Reference: https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/
hi @tennaki,
did you searched a little before asking ? ๐
This subject was handled many times in the past.
https://buddypress.org/support/search/notifications+counter/
I’m curious if there’s any way I could have the notification number that is on the admin bar moved to a page link on the menu bar on my website.
I’m trying to get my BuddyPress-enabled website to a point where our registered users do not need to see the admin bar, but having the notifications counter is something I’d like to keep.
Hey guys !
I am searching since one week for a solution of my problem.
My idea is to create 2 icons in my topbar (no bp-admin-bar, i have an own seperate topbar). I have already create a counter for notification and friends and have a dropdown function.
In the friends dropdown i have input the code from friends-request.php and if you click on the icon there is an dropdown which shows the reqeuest. The problem is that it only shows the reqeust inside the dropdown if you are on a profilpage.
If you hit the notification icon there should be only show new notifications and no friend requests.
At the moment it shows everything.
For the counter i use this function:
<?php
function bpfr_add_notification_to_page_title( ) {
//do not change if the user is not logged in
if( ! is_user_logged_in() )
$user_id = get_current_user_id();//logged in user's id
$count = bp_notifications_get_unread_notification_count( $user_id );
if( $count > 0 )
$title = sprintf( "You Have %d New Notification(s) - ", $count );
$anzahlNeuigkeiten = $count;
echo '<a class="news" data-dropdown="news" aria-controls="autoCloseExample" aria-expanded="false"> <i class="fi-megaphone" ></i></a><span class="update" >'.$anzahlNeuigkeiten.'</span>';
echo '<a style="margin-left:10px;" class="frequest" data-dropdown="friendrequest" aria-controls="autoCloseExample" aria-expanded="false"><i class="fi-torsos"></i></a><span class="update">';
echo bp_friend_get_total_requests_count( bp_loggedin_user_id() ) ;
echo '</span>';
}
?>
I found already a thread which trys to explain how to fix it ”
How to split out BuddyPress notifications drop down items to their own top level” but there is no content for the dropdown.
So my question is . How can I show the requests of friends in the dropdown on every page? And how can filter notifications? It should be like on Facebook, if you hit the friends icon then it shows requests. If you hit the notification icon than it shows news.
Thannk you guys for your help !
Best Regards !
Peter
@danbp
I have edited the code a bit and now it is getting displayed on all the pages as I wanted but, How can I hide the modified title when the notification count is 0. By current code is below –
function bpfr_add_notification_to_page_title( $title, $original_title, $sep, $seplocation ) {
global $bp;
if( bp_is_user() && ! bp_get_member_user_id() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
if (bp_notifications_get_unread_notification_count( $user_id ) ) {
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
echo $notifications[$i];
$counter++;
}
$title = "You Have " . bp_notifications_get_unread_notification_count() . " New Notification(s) - ";
return $title;
}
}
add_filter( 'wp_title', 'bpfr_add_notification_to_page_title', 9, 4 );
Thanks
Try this (tested on 2.2 RC2)
function bpfr_add_notification_to_page_title( $title, $original_title, $sep, $seplocation ) {
global $bp;
if( bp_is_user() && ! bp_get_member_user_id() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
if (bp_notifications_get_unread_notification_count( $user_id ) ) {
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
echo $notifications[$i];
$counter++;
}
if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) ) {
$title .= bp_notifications_get_unread_notification_count() . " $sep ";
}
return $title;
}
}
add_filter( 'bp_modify_page_title', 'bpfr_add_notification_to_page_title', 9, 4 );
Try this
if ( $notifications = bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) ) {
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
echo '<span ="'.$alt.'">'. $notifications[$i] .'</span>';
$counter++;
}
Thxs @shanebp, i ignored that. ๐
Corrected function here:
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_notifications_get_notifications_for_user( $user_id, $format = 'string' ) ) {
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
echo '<p ="'.$alt.'"><i class="fa fa-group"></i>'. $notifications[$i] .'</p>';
$counter++;
}
}
}
Shows anything group related to the concerned group member.
Mentions, membership request/reject, promotion,…
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 ! ๐
@sebacar @mercime Hi Sebastien, from looking at replies to your Trac ticket, I think something is being lost in translation between ourselves and the devs.
To quote the official documentation :
Notifications are a central aspect of the user experience on a BuddyPress site. By default new notifications are displayed in the admin bar profile menu, right next to the navigation menus, some themes even integrate the notification counter in other places (like in the header or sidebar of a page).
Notifications are sent out to your community members as soon as one of the following things happen:
Activity
A member mentions you in an update @usernameโ
A member replies to an update or comment youโve posted
The activity in bold above definitely stopped triggering notifications on 3 different sites I was testing, where it had previously generated a notification (probably 4 months+ consistently). Quite simply, that notification trigger stopped working. This should not be a new feature, it was already there.
Hi guys,
I’ve spent ages this morning disabling all plugins and systematically working back through them to find the culprit.
It turns out it’s Paid Memberships PRO that is being a little tricky with Buddypress.
When PMP isn’t activated, I get the usual nice plain text notifications through Buddypress and BBPress for things like New Messages, Friend Requests etc.
Something like;
‘Hi John, How Are’
—–
This was sent to you…..
When I enable PMP I get the same notification e-mails, but it’s all scrambled without any formatting, so it looks more like
‘Hi John, How Are’—This was sent to you because…To unsubscribe etc.
Has anybody else encountered this annoying formatting issue? Or does anyone have any ideas how it could be resolved?
Thanks a million guys – I’m totally stuck on this one!
Hello everyone,
Was just wondering if it’s possible to reset the blue oval and Howdy drop-down notifications counters. We have a member who just cannot get the digit in the blue oval to correspond to the notifications on the Howdy! drop down menu.
Is it possible to reset one or all of the accounts’ notifications totals?
This is an extreme nuisance for the users we have that are frequent visitors to the site.
Thanks,
Bart
Hello, i’m using the latest BP release with the latest WP release but unfortunately some counters does not working correctly for me. Here a picture:
Here the direct site:
There is one group created, and the counter for groups is not showing 1 but count, reverse other counters does not show correctly the zero numeber (show no-count)
I recently disabled with code the “Register” page, the one of BP, and also installed a registration anti-spam software.
Already tried myself to change the original code i found: bp_get_total_group_count_for_user() with the only one is working for me (notifications): bp_get_total_group_count_for_user( bp_loggedin_user_id() )
But this does not work. A little help should be creately appreciated… Stefano
Hi @transmission,
this is not the solution, but an example for your inspiration.
The below shows how the notification counter can be moved/implemented on the toolbar.
/* moving the notification counter from right to left */
remove_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
function bpfr_notification_ontheleft() {
global $wp_admin_bar;
if ( !is_user_logged_in() )
return false;
$notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
$count = !empty( $notifications ) ? count( $notifications ) : 0;
$alert_class = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
$menu_title = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . $count . '</span>';
// Add the top-level Notifications button
$wp_admin_bar->add_menu( array(
/*'parent' => 'top-secondary',*/ // this is the original position
'id' => 'bp-notifications',
'title' => $menu_title,
'href' => bp_loggedin_user_domain(),
) );
if ( !empty( $notifications ) ) {
foreach ( (array) $notifications as $notification ) {
$wp_admin_bar->add_menu( array(
'parent' => 'bp-notifications',
'id' => 'notification-' . $notification->id,
'title' => $notification->content,
'href' => $notification->href
) );
}
} else {
$wp_admin_bar->add_menu( array(
'parent' => 'bp-notifications',
'id' => 'no-notifications',
'title' => __( 'No new notifications', 'buddypress' ),
'href' => bp_loggedin_user_domain()
) );
}
return;
}
add_action( 'admin_bar_menu', 'bpfr_notification_ontheleft',30);
/* other position # are 10, 20, 40, 50, 60, 70, 80, 90 */
In your case, you also have to check this Codex page. And possibly do some research here.
hi @pascalh,
your issue maybe related to your theme or a custom function you use.
The original “notifications” string is in bp-notifications/bp-notifications-loader.php:109
Check the po file first
If you made a custom function to get the menu, check that function.
Be aware that the words “notifications”, “friends” and “groups” are coming with a count and that this counter is included in the translation within a html span tag. This is technically the point who made such translation not showing in some case. Because gettext is not very compleasant with html tags… So the problem can also be the strictness of the php version on use on your server.
You can test this by writing your translation without using the span tag. (meldingen %d for example). If this ok, you’ll be fixed.
@pjbursnall Personally I think buddypress should disable admin access anyway as most users don’t want it but that is neither here nor there. Recreating the admin bar is pretty easy, you need to know some css, html and a few bp functions to get the current users details like username etc, as for the notifications @modemlooper or @mercime posted this a while back (my apologies for not remembering which).
function bp_notification_badge() {
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
$notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id() );
if ( empty($notifications)) {
echo '<li class="li-first" id="li-first-right"><a href="' . get_home_url() . '/members/' . $current_user->user_login . '"><span class="circle-zero">0</span></a><ul class="second-level" id="second-level-right"><li class="li-second"><a href="' . get_home_url() . '/members/' . $current_user->user_login . '">No new notifications!</a></li></ul></li>';
} else {
echo '<ul class="second-level" id="second-level-right">';
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
$badge = count($notifications);
echo '<li class="li-third">'.$notifications[$i].'</li>';
}
echo '</ul>';
echo '<a href="' . get_home_url() . '/members/' . $current_user->user_login . '"><span class="circle-badge">'.$badge.'</span></a>';
}
}
}
As for actually disabling the admin bar + backend that can be done with a plugin, plenty of them just google.
@espellcaste
do you have some news?
I have been able to take the notifications like this :
// notifications
function my_bp_adminbar_notifications_menu() {
global $bp;
if ( !is_user_logged_in() )
return false;
echo '<li id="menu-item-9991" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9991 parent">';
// _e( 'Alerts', 'buddypress' );
if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
<a href="#"><span id="notifs_top"><?php echo count( $notifications ) ?></span></a>
<?php
}
echo '</a>';
echo '<ul class="sub-menu">';
if ( $notifications ) {
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
<li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
<?php $counter++;
}
} else { ?>
<li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'You have no new alerts.', 'buddypress' ); ?></a></li>
<?php
}
echo '</ul>';
echo '</li>';
}
You can make your own. Here’s mine as an example. You’ll need to tinker around with the CSS or code if you’d like to display them differently. What the below does is it shows a number (the amount of notifications you have) when you have one or more. It is hidden when there are none to display. Hovering over the number will display your notifications in a drop-down.
Place into bp-custom.php:
/**
* Add Notification number to template
*/
function my_bp_adminbar_notifications_menu() {
global $bp;
if ( !is_user_logged_in() )
return false;
echo '<div class="notices"><ul class="notices">';
_e( '', 'buddypress' );
if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
<li class="parent"><span class="notice-badge"><?php echo count( $notifications ) ?></span>
<?php
}
echo '</a>';
echo '<ul class="sub-menu">';
if ( $notifications ) {
$counter = 0;
for ( $i = 0; $i < count($notifications); $i++ ) {
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
<li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
<?php $counter++;
}
} else { ?>
<li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'You have no new alerts.', 'buddypress' ); ?></a></li>
<?php
}
echo '</ul></li>';
echo '</ul></div>';
}
CSS:
/*-------------------------- Notification dropdown -----------------------------------*/
.notice-badge { font-weight: bold; cursor: default; background: #d33939; padding: 0 3px; border-radius: 10px }
.parent.user-bar { width: 86px; text-align:left; float: right; font-weight: bold; }
.notices { float: right; margin:0; line-height: 45px; z-index: 9999; }
.notices a { color: #ffffff; }
.notices ul, .notices { margin:0 2px 0 0; padding:0; list-style-type:none; list-style-position:outside; position:relative; }
.notices ul a:link, .notices ul a:active, .notices ul a:visited { display:block; padding: 0; text-decoration:none; }
.notices ul ul a:link, .notices ul ul a:active, .notices ul ul a:visited { width: 480px; display:block; padding:0 7px; text-decoration:none; }
.notices ul ul a:hover { color: #0d385f; text-shadow: none; }
.notices ul li { float:left; position:relative; background:none; padding:0 12px; }
.notices ul li:hover { transition: all 100ms ease-in; }
.notices ul ul { width: 480px; line-height: 35px; background: #ffffff; position:absolute; right: 0; top:45px; text-align:left; padding:0; display:none; border:1px solid #eeeeee; border-bottom:none; border-top:none; box-shadow:0 0 2px rgba(0, 0, 0, 0.15), 0 3px 5px rgba(0, 0, 0, 0.1); }
.notices ul ul a { color:#248361; font-weight: bold; }
.notices ul li ul a { float:left; }
.notices ul li ul ul { left:-170px; top:2px; margin:0px; border-right:3px solid #cccccc; border-top:1px solid #eeeeee; }
.notices ul li ul li { width: 480px; padding:0; margin:0; border-bottom:1px solid #eeeeee; max-width:none; list-style-type:none; text-shadow: none; }
.notices ul li ul li:hover { background: #f5f5f5; }
.noticesn ul li:hover ul ul, ul li:hover ul ul ul, ul li:hover ul ul ul ul { display:none; }
.notices ul li:hover ul, .notices ul li li:hover ul, .notices ul li li li:hover ul, .notices ul li li li li:hover ul { display:block; }
.notices ul li ul.children li { list-style-type:none; }
.notices ul li ul li.current-menu-item { background:#f5f5f5; }
.notices ul li ul li.current-menu-item a { color:#585858; }
.notices ul li.current-menu-item span { color:#585858; }
.notices ul li.parent { background-image: url(images/menu-arrow-transparent.png); background-position: center center; background-repeat: no-repeat; }
.notices ul li.parent:hover { background-image: url(images/menu-arrow1.png); background-position: 14px 36px; background-repeat: no-repeat; }
.notices ul li ul li.parent:hover { background-image: url(images/menu-arrow-left.png); background-position: 152px center; background-repeat: no-repeat; }
Place into header.php or wherever you’d like your notifications shown:
<?php my_bp_adminbar_notifications_menu()?>
@chouf1 thank you. This really works.
Is there any idea that it works the same for the front end of the website too?
I mean by applying the above code the counter moves at the back end bar but when visits the front end there, at bar, the counter still remains on the right side.
I would love to listen. Again, thank you so much.
here’re the 3 counter. Their names are explicit enough i guess to see the right place where to use ๐
echo bp_friend_get_total_requests_count( $user_id );
echo bp_get_total_unread_messages_count($name );
echo count($notifications);
First of all, loving the new release!
The Notifications in the WP bar is AWESOME.
I’ve encountered an error though that was not present prior to updating.
Previously, if someone made an Activity Stream post, and another user commented on that post, the original author would get a BP Notification that a comment was added to their post.
This is no longer happening. After replying to a stream post, the original poster still has 0 notifications.
I do not know if this is also happening with other ‘events’ as well, but it certainly is with stream commenting.
Advice please?
This has to be a bug. I’ve encountered this with two separate installs of WordPress/BuddyPress. The first install was not done by me… I was hired by a client to test out the site. After spending more than a week on the error I decided to do a fresh install on my own server. I followed all Bp Install instruction… and I am very comfortable with doing Wp installs -can do them in my sleep…
Please Read –
Error that I am receiving: Page not found. We’re sorry, but we can’t find the page that you’re looking for. Perhaps searching will help.
However, I do not receive this error on all pages… All my main Bp pages work as they should (on both installs)… HOME , ACTIVITY, GROUPS, MEMBERS… As well as pages (menu links) that are in the admin bar (top of site).
Instead I get the PAGE NOT FOUND error on the following menu items:
-Groups / Membership – http://design911.net/main/_client_work/groups/members/admin/groups/my-groups/
-Groups / Invitations – http://design911.net/main/_client_work/groups/members/admin/groups/invites/
I also get this errors when attempting to check notifications from Group Invites…
Not sure what to do next. Please help.
Since search is still down here, forgive me if this is a repeat topic. Basically wondering if anyone else has encountered this and can provide a solution. Basically install the BuddyPress Skeleton Component into WP 3.2 / BP 1.2.9.
The example menu tab examples work EXCEPT for the example under the settings tab (where general and notifications are for the profile). The menu tab is visible, but click it and you get redirected on the homepage. Maybe this is due to some hooks being moved or switched around – I know the skeleton component is showing it’s age but wondering if perhaps anyone can point me in the right direction. OR if anyone knows of a plugin that currently adds a menu choice under user settings.