Notification API – How do I add something to the notification part of the admin bar?
-
I’m looking to add a simple notification to the notification part of the admin bar. Then when they go to a specific page the notification will go away.
Can anyone provide me with a basic code chunk I can modify to my needs? Or provide any hints? lol
thank you
-
@anonymized-96400
InactiveWhen you setup the globals of your plugin you can specify a notification function like so:
`function log_setup_globals()
{
global $bp;// some stuff here
$bp->logbooks->format_notification_function = ‘log_format_notifications’;
// some more stuff here
}
add_action( ‘bp_setup_globals’, ‘log_setup_globals’ );`This function might look something like this then:
`function log_format_notifications( $action, $item_id, $secondary_item_id, $total_items )
{
global $bp;if( ‘new_dive’ == $action )
{
if ( (int)$total_items > 1 )
return apply_filters( ‘log_multiple_verifications_notification’, ‘loggedin_user->domain . ‘logbook/verifications/” title=”‘ . __( ‘Verifications’, ‘logs’ ) . ‘”>’ . sprintf( __(‘You have %d new logbook verifications’, ‘logs’ ), (int)$total_items ) . ‘‘, $total_items );
else
return apply_filters( ‘log_single_verification_notification’, ‘loggedin_user->domain . ‘logbook/verifications/” title=”‘ . __( ‘Verifications’, ‘logs’ ) . ‘”>’ . sprintf( __(‘You have %d new logbook verification’, ‘logs’ ), (int)$total_items ) . ‘‘, $total_items );
}do_action( ‘log_format_notifications’, $action, $item_id, $secondary_item_id, $total_items );
return false;
}`You can then remove these notifications with a function like this:
`function log_remove_screen_notifications()
{
global $bp;bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->logbooks->name, ‘new_dive’ );
}
add_action( ‘log_verifications_screen’, ‘log_remove_screen_notifications’ );`For this to work you have to place the do_action call to log_verifications_screen on the page that is linked in the notification.
To record a notification you call this function like so:
`bp_core_add_notification( $dive_id, $user_id, ‘logbooks’, ‘new_dive’ );`I copied the above from a plugin I’m working on at the moment. Also, have a look at the skeleton component and the various BP functions.
Enjoy!
@travel-junkie Great thanks for the tips. I’ll try some things this week on it. How would I turn off notifications for a specific event from a general user point of view? Via My account > settings > notifications ?
@anonymized-96400
InactiveYou can only turn email notifications off via that settings page. Notifications in the admin bar are different. You’d have to code it into the above functions if you only want notifications on specific events.
Ya, turning off email notifications alone is fine Thanks again for your direction! Hopefully I can figure this out, lol. Probably take a while though since I’m a noob.
@travel-junkie Can you explain what each of the functions are doing? I’m still not fully understanding this.. sorry
I’ve looked at the skeleton component but it’s so different from what I’m trying to do. I don’t want to give another person a “high five” or accept a agreement.
- The topic ‘Notification API – How do I add something to the notification part of the admin bar?’ is closed to new replies.