Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I create a notification?

  • Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I’m trying to create a plugin that would rely on bp’s notification system. I looked in the codex and wasn’t able to find any guidance. Can anyone walk me through notifications, in terms of how to trigger it, where it gets stored, what bp actions are required, etc?

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    anyone? this looks like my starting point:

    function bp_core_add_notification

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    Just to start building this out as a how-to:

    To add a notification, you would call this function located in bp-core-notifications.php

    bp-core-notifications; function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false )

    So as a test, if you wanted to store a notification that the user had just visited the activity page, you could make up a new notification type ‘activity_viewed’ and use this code:

    bp_core_add_notification('100', (int)$bp->loggedin_user->id, 'activity', 'activity_viewed');

    Of course, that’s useless unless we ping the user. Next step: how do we add the little notification to the buddy bar? Any ideas?

    Avatar of gian-ava
    gian-ava
    Participant

    @gian-ava

    I am really interested in this.

    I did re-create the admin bar to fit my design and got rid of the default one.

    Now, I want to re-produce the notifications system.

    Is that what you’re trying to achive?

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I still can’t figure out how to ping the user. This would be a good topic for Buddypress Gurus to think about for a FAQ or developer guide.

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    The best way to figure these things out is to look at how the default BP system does it~!

    Look at how friendship notifications are made in bp-friends.php and bp-friends-notifications.php

    1) Create a function that contains the bp_core_add_notification() and hook it into a particular BP action.

    You probably did not hook your custom function to any BP action, that’s why it isn’t doing anything.

    2) Format the notification.

    Here, you create a new function that formats the notification. You will use the $component_action you defined in your custom function from bp_core_add_notification(). You will hook this new function into the core component’s notification function.

    Look at friends_format_notifications() in bp-friends.php for more info.

    3) Delete the notification.

    You’ll probably want to delete the notification when someone has viewed it!

    Create a function with one of the notification delete functions in bp-core-notifications.php and hook it to a BP action.

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    bingo. I need a step 2. It’s always step 2 I forget about!!

    I will play with this. My goal is to generate a generic “skeleton notification” system that other folks can adapt.

    THANK YOU!!

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

You must be logged in to reply to this topic.