bp_notifications_toolbar_menu()

Build the “Notifications” dropdown.

Description

Return

(bool)

Source

File: bp-notifications/bp-notifications-adminbar.php

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function bp_notifications_toolbar_menu() {
    global $wp_admin_bar;
 
    if ( ! is_user_logged_in() ) {
        return false;
    }
 
    $notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
    $count         = ! empty( $notifications ) ? count( $notifications ) : 0;
    $alert_class   = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
    $menu_title    = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . number_format_i18n( $count ) . '</span>';
    $menu_link     = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
 
    // Add the top-level Notifications button.
    $wp_admin_bar->add_menu( array(
        'parent'    => 'top-secondary',
        'id'        => 'bp-notifications',
        'title'     => $menu_title,
        'href'      => $menu_link,
    ) );
 
    if ( ! empty( $notifications ) ) {
        foreach ( (array) $notifications as $notification ) {
            $wp_admin_bar->add_menu( array(
                'parent' => 'bp-notifications',
                'id'     => 'notification-' . $notification->id,
                'title'  => $notification->content,
                'href'   => $notification->href,
            ) );
        }
    } else {
        $wp_admin_bar->add_menu( array(
            'parent' => 'bp-notifications',
            'id'     => 'no-notifications',
            'title'  => __( 'No new notifications', 'buddyboss' ),
            'href'   => $menu_link,
        ) );
    }
 
    return;
}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.