Skip to:
Content
Pages
Categories
Search
Top
Bottom

BP Direct Menus – Adding notifications


  • Kieran
    Participant

    @naughtybiscuit

    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

Viewing 4 replies - 1 through 4 (of 4 total)

  • godavid33
    Participant

    @godavid33

    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,
    Gabe


    DarkElement1987
    Participant

    @darkelement1987

    Awesome, i hope this works, then i can finally remove the stupid admin bar. @godavid33 In what functions.php file do i put it?


    DarkElement1987
    Participant

    @darkelement1987

    I don’t get this whole plugin to work, this is my output:

    http://oi57.tinypic.com/rvai5g.jpg


    Kieran
    Participant

    @naughtybiscuit

    @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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘BP Direct Menus – Adding notifications’ is closed to new replies.
Skip to toolbar