Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Notification API – How do I add something to the notification part of the admin bar?


Anonymous User 96400
Inactive

@anonymized-96400

When 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!

Skip to toolbar