Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/06/2011 07:10:08 PM (14 years ago)
Author:
boonebgorges
Message:

Provides initial support for Notifications menu in WP Admin Bar. Refactors group and friendship notifications to return values compatible with the WP Admin Bar constructor. Modifies bp_core_get_notifications_for_user() in order to provide WP Admin Bar support in addition to BuddyBar backpat. References #3294

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-members/bp-members-adminbar.php

    r4586 r4620  
    7373 * @since 1.3
    7474 */
    75 function bp_members_user_admin_menu() {
     75function bp_members_admin_bar_user_admin_menu() {
    7676    global $bp, $wp_admin_bar;
    7777
     
    146146    ) );
    147147}
    148 add_action( 'bp_setup_admin_bar', 'bp_members_user_admin_menu', 99 );
     148add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_user_admin_menu', 99 );
     149
     150/**
     151 * Build the "Notifications" dropdown
     152 *
     153 * @package Buddypress
     154 * @since 1.3
     155 */
     156function bp_members_admin_bar_notifications_menu() {
     157    global $bp, $wp_admin_bar;
     158
     159    if ( !is_user_logged_in() )
     160        return false;
     161       
     162    if ( $notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id(), 'object' ) ) {
     163        $menu_title = sprintf( __( 'Notifications <span id="ab-pending-notifications" class="pending-count">%s</span>', 'buddypress' ), count( $notifications ) );
     164    } else {
     165        $menu_title = __( 'Notifications', 'buddypress' );
     166    }
     167   
     168    // Add the top-level Notifications button
     169    $wp_admin_bar->add_menu( array(
     170        'id'    => 'notifications',
     171        'title' => $menu_title,
     172        'href'  => bp_loggedin_user_domain()
     173    ) );
     174   
     175    if ( !empty( $notifications ) ) {
     176        foreach ( (array)$notifications as $notification ) {
     177            $wp_admin_bar->add_menu( array(
     178                'parent' => 'notifications',
     179                'id'     => 'notification-' . $notification->id,
     180                'title'  => $notification->content,
     181                'href'   => $notification->href
     182            ) );
     183        }
     184    } else {
     185        $wp_admin_bar->add_menu( array(
     186            'parent' => 'notifications',
     187            'id'     => 'no-notifications',
     188            'title'  => __( 'No new notifications', 'buddypress' ),
     189            'href'   => bp_loggedin_user_domain()
     190        ) );
     191    }
     192   
     193    return;
     194}
     195add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_notifications_menu', 999 );
    149196
    150197/**
Note: See TracChangeset for help on using the changeset viewer.