BP Direct Menus – Adding notifications
-
Hey,
My goal is to attempt to remove the admin bar completely but not to lose the functionality it provides, I’ve been using a plugin called BP Direct Menus to add a count at the end of the menu item. For example where my menu item is ‘Messages’ I add %(unreadmessagecount)% in the menu title and the plugin converts that to ‘Messages (1)’ when it has a new message.
This plugin doesn’t have any feature for notifications and I’ve tried a brief fiddle with the files but I have been unable to get a notification count due to my lack of skill and knowledge in this area. (unfortunately the dev doesn’t seem to be around anymore)
The GitHub for this project is https://github.com/mrwulf/bp-direct-menu/blob/master/bp-direct-menu/inc/frontend-noajax.inc.php
In my attempts I have only managed to print ‘Notifications (ARRAY)’ so I am definitely going wrong somewhere.
Does anyone have any insight (with regards to this plugin) on how to get the notification count for BuddyPress?
Thanks,
Kieran
-
Awesome, a post that isn’t years old that I may actually be able to help!
In functions.php add the following function:
function cg_current_user_notification_count() { $notifications = bp_core_get_notifications_for_user(bp_loggedin_user_id(), 'object'); $count = !empty($notifications) ? count($notifications) : 0; return $count; }
In frontend-noajax.inc.php (you can find this in plugins/bp-direct-menus/inc) add the following code around line 150 (near where all the counts are initialized):
$notifcount = cg_current_user_notification_count(); $item->title = str_ireplace("%notificationcount%", $notifcount, $item->title); $item->title = str_ireplace("%(notificationcount)%", ($notifcount > 0) ? '('.$notifcount.')' : '', $item->title);
Hope that helps you, or if you already figured it out, helps somebody else.
Cheers,
GabeAwesome, i hope this works, then i can finally remove the stupid admin bar. @godavid33 In what functions.php file do i put it?
I don’t get this whole plugin to work, this is my output:
@godavid33 Hey thanks very much for your response, I figured out something similar a little while ago and unfortunately I forgot about this forum post. Will try out your code on my test server later on.
Thank you very much for your time and effort on this, and again, sorry for the very late reply.
- The topic ‘BP Direct Menus – Adding notifications’ is closed to new replies.